src/Doc/Datatypes/Datatypes.thy
changeset 52794 aae782070611
parent 52792 3e651be14fcd
child 52795 126ee2abed9b
equal deleted inserted replaced
52793:062aa11e98e1 52794:aae782070611
     9 begin
     9 begin
    10 
    10 
    11 section {* Introduction *}
    11 section {* Introduction *}
    12 
    12 
    13 text {*
    13 text {*
    14   * Isabelle2013 introduced new definitional package for datatypes and codatatypes
    14 The 2013 edition of Isabelle introduced new definitional package for datatypes
    15 
    15 and codatatypes. The datatype support is similar to that provided by the earlier
    16   * datatype support is similar to old package, due to Berghofer \& Wenzel \cite{xxx}
    16 package due to Berghofer and Wenzel \cite{Berghofer-Wenzel:1999:TPHOL};
    17     * indeed, replacing \cmd{datatype} by \cmd{datatype\_new} is usually sufficient
    17 indeed, replacing \cmd{datatype} by \cmd{datatype\_new} is usually sufficient
    18       to port existing specifications to the new package
    18 to port existing specifications to the new package. What makes the new package
    19 
    19 attractive is that it supports definitions with recursion through a large class
    20   * but it is more powerful, because it is now possible to have nested recursion
    20 of non-datatypes, notably finite sets:
    21     through a large class of non-datatypes, notably finite sets:
       
    22 *}
    21 *}
    23 
    22 
    24 datatype_new 'a tree = Node 'a "('a tree fset)"
    23 datatype_new 'a tree = Node 'a "('a tree fset)"
    25 
    24 
    26 text {*
    25 text {*
    27   * another advantage: it supports local definitions:
    26 \noindent
       
    27 Another advantage of the new package is that it supports local definitions:
    28 *}
    28 *}
    29 
    29 
    30 context linorder
    30 context linorder
    31 begin
    31 begin
    32 
    32   datatype_new flag = Less | Eq | Greater
    33 datatype_new flag = Less | Eq | Greater
       
    34 
       
    35 end
    33 end
    36 
    34 
    37 text {*
    35 text {*
    38 
    36 \noindent
    39  * in a future release, \cmd{datatype\_new} is expected to displace \cmd{datatype}
    37 Finally, the package also provides some convenience, notably automatically
    40 
    38 generated destructors. For example, the command
    41  * 
    39 *}
    42 *}
    40 
       
    41 (*<*)hide_const Nil Cons hd tl(*>*)
       
    42 datatype_new 'a list = null: Nil | Cons (hd: 'a) (tl: "'a list")
       
    43 
       
    44 text {*
       
    45 \noindent
       
    46 introduces a discriminator @{const null} and a pair of selectors @{const hd} and
       
    47 @{const tl} characterized as follows:
       
    48 
       
    49 @{thm [display] list.collapse[no_vars]}
       
    50 
       
    51 The command \cmd{datatype\_new} is expected to displace \cmd{datatype} in a future
       
    52 release. Authors of new theories are encouraged to use \cmd{datatype\_new}, and
       
    53 maintainers of older theories might want to consider upgrading now.
       
    54 
       
    55 The package also provides codatatypes (or ``coinductive datatypes''), which may
       
    56 have infinite values. The following command introduces a type of infinite
       
    57 streams:
       
    58 *}
       
    59 
       
    60 codatatype 'a stream = Stream 'a "('a stream)"
       
    61 
       
    62 text {*
       
    63 \noindent
       
    64 Mixed inductive--coinductive recursion is possible via nesting.
       
    65 Compare the following four examples:
       
    66 *}
       
    67 
       
    68 datatype_new 'a treeFF = TreeFF 'a "('a treeFF list)"
       
    69 datatype_new 'a treeFI = TreeFI 'a "('a treeFF stream)"
       
    70 codatatype 'a treeIF = TreeIF 'a "('a treeFF list)"
       
    71 codatatype 'a treeII = TreeII 'a "('a treeFF stream)"
       
    72 
       
    73 text {*
       
    74 To use the package, it is necessary to import the @{theory BNF} theory, which
       
    75 can be precompiled as the \textit{HOL-BNF}:
       
    76 *}
       
    77 
       
    78 text {*
       
    79 \noindent
       
    80 \texttt{isabelle build -b HOL-BNF}
       
    81 *}
       
    82 
       
    83 text {*
       
    84   * TODO: LCF tradition
       
    85   * internals: LICS paper
       
    86 *}
       
    87 
       
    88 text {*
       
    89 This tutorial is organized as follows:
       
    90 
       
    91   * datatypes
       
    92   * primitive recursive functions
       
    93   * codatatypes
       
    94   * primitive corecursive functions
       
    95 
       
    96 the following sections focus on more technical aspects:
       
    97 how to register bounded natural functors (BNFs), i.e., type
       
    98 constructors via which (co)datatypes can (co)recurse,
       
    99 and how to derive convenience theorems for free constructors,
       
   100 as performed internally by \cmd{datatype\_new} and \cmd{codatatype}.
       
   101 
       
   102 then: Standard ML interface
       
   103 
       
   104 interaction with other tools
       
   105   * code generator (and Quickcheck)
       
   106   * Nitpick
       
   107 *}
       
   108 
       
   109 section {* Registering Bounded Natural Functors *}
       
   110 
       
   111 subsection {* Introductory Example *}
       
   112 
       
   113 subsection {* General Syntax *}
       
   114 
       
   115 section {* Generating Free Constructor Theorems *}
    43 
   116 
    44 section {* Defining Datatypes *}
   117 section {* Defining Datatypes *}
    45 
   118 
    46 text {*
   119 subsection {* Introductory Examples *}
    47   * theory to include
   120 
    48 *}
   121 subsubsection {* Nonrecursive Types *}
       
   122 
       
   123 subsubsection {* Simple Recursion *}
       
   124 
       
   125 subsubsection {* Mutual Recursion *}
       
   126 
       
   127 subsubsection {* Nested Recursion *}
       
   128 
       
   129 subsubsection {* Auxiliary Constants *}
       
   130 
       
   131 subsection {* General Syntax *}
       
   132 
       
   133 subsection {* Characteristic Theorems *}
       
   134 
       
   135 subsection {* Compatibility Issues *}
       
   136 
    49 
   137 
    50 section {* Defining Primitive Recursive Functions *}
   138 section {* Defining Primitive Recursive Functions *}
    51 
   139 
       
   140 subsection {* Introductory Examples *}
       
   141 
       
   142 subsection {* General Syntax *}
       
   143 
       
   144 subsection {* Characteristic Theorems *}
       
   145 
       
   146 subsection {* Compatibility Issues *}
       
   147 
       
   148 
    52 section {* Defining Codatatypes *}
   149 section {* Defining Codatatypes *}
    53 
   150 
       
   151 subsection {* Introductory Examples *}
       
   152 
       
   153 subsection {* General Syntax *}
       
   154 
       
   155 subsection {* Characteristic Theorems *}
       
   156 
       
   157 
    54 section {* Defining Primitive Corecursive Functions *}
   158 section {* Defining Primitive Corecursive Functions *}
    55 
   159 
       
   160 subsection {* Introductory Examples *}
       
   161 
       
   162 subsection {* General Syntax *}
       
   163 
       
   164 subsection {* Characteristic Theorems *}
       
   165 
       
   166 subsection {* Compatibility Issues *}
       
   167 
       
   168 
    56 section {* Registering Bounded Natural Functors *}
   169 section {* Registering Bounded Natural Functors *}
    57 
   170 
       
   171 subsection {* Introductory Example *}
       
   172 
       
   173 subsection {* General Syntax *}
       
   174 
       
   175 
    58 section {* Generating Free Constructor Theorems *}
   176 section {* Generating Free Constructor Theorems *}
    59 
   177 
    60 section {* Conclusion *}
   178 subsection {* Introductory Example *}
       
   179 
       
   180 subsection {* General Syntax *}
       
   181 
       
   182 section {* Registering Bounded Natural Functors *}
       
   183 
       
   184 section {* Standard ML Interface *}
       
   185 
       
   186 section {* Interoperability Issues *}
       
   187 
       
   188 subsection {* Transfer and Lifting *}
       
   189 
       
   190 subsection {* Code Generator *}
       
   191 
       
   192 subsection {* Quickcheck *}
       
   193 
       
   194 subsection {* Nitpick *}
       
   195 
       
   196 subsection {* Nominal Isabelle *}
       
   197 
       
   198 section {* Known Bugs and Limitations *}
       
   199 
       
   200 text {*
       
   201 * slow n-ary mutual (co)datatype, avoid as much as possible (e.g. using nesting)
       
   202 *}
    61 
   203 
    62 end
   204 end