equal
deleted
inserted
replaced
6 |
6 |
7 Tutorial for (co)datatype definitions with the new package. |
7 Tutorial for (co)datatype definitions with the new package. |
8 *) |
8 *) |
9 |
9 |
10 theory Datatypes |
10 theory Datatypes |
11 imports Setup |
11 imports Setup "~~/src/HOL/Library/Simps_Case_Conv" |
12 begin |
12 begin |
13 |
13 |
14 section {* Introduction |
14 section {* Introduction |
15 \label{sec:introduction} *} |
15 \label{sec:introduction} *} |
16 |
16 |
1050 "tfold _ (TNil y) = y" | |
1050 "tfold _ (TNil y) = y" | |
1051 "tfold f (TCons x xs) = f x (tfold f xs)" |
1051 "tfold f (TCons x xs) = f x (tfold f xs)" |
1052 |
1052 |
1053 text {* |
1053 text {* |
1054 \noindent |
1054 \noindent |
|
1055 Pattern matching is only available for the argument on which the recursion takes |
|
1056 place. Fortunately, it is easy to generate pattern-maching equations using the |
|
1057 \keyw{simps\_of\_case} command provided by the theory |
|
1058 \verb|~~/src/HOL/Library/Simps_Case_Conv|. |
|
1059 *} |
|
1060 |
|
1061 simps_of_case at_simps: at.simps |
|
1062 |
|
1063 text {* |
|
1064 This generates the lemma collection @{thm [source] at_simps}: |
|
1065 % |
|
1066 \[@{thm at_simps(1)[no_vars]} |
|
1067 \qquad @{thm at_simps(2)[no_vars]}\] |
|
1068 % |
1055 The next example is defined using \keyw{fun} to escape the syntactic |
1069 The next example is defined using \keyw{fun} to escape the syntactic |
1056 restrictions imposed on primitive recursive functions. The |
1070 restrictions imposed on primitive recursive functions. The |
1057 @{command datatype_new_compat} command is needed to register new-style datatypes |
1071 @{command datatype_new_compat} command is needed to register new-style datatypes |
1058 for use with \keyw{fun} and \keyw{function} |
1072 for use with \keyw{fun} and \keyw{function} |
1059 (Section~\ref{sssec:datatype-new-compat}): |
1073 (Section~\ref{sssec:datatype-new-compat}): |
1757 LNil \<Rightarrow> ys |
1771 LNil \<Rightarrow> ys |
1758 | LCons x xs' \<Rightarrow> LCons x (lappend xs' ys))" |
1772 | LCons x xs' \<Rightarrow> LCons x (lappend xs' ys))" |
1759 |
1773 |
1760 text {* |
1774 text {* |
1761 \noindent |
1775 \noindent |
|
1776 Pattern matching is not supported by @{command primcorec}. Fortunately, it is |
|
1777 easy to generate pattern-maching equations using the \keyw{simps\_of\_case} |
|
1778 command provided by the theory \verb|~~/src/HOL/Library/Simps_Case_Conv|. |
|
1779 *} |
|
1780 |
|
1781 simps_of_case lappend_simps: lappend.code |
|
1782 |
|
1783 text {* |
|
1784 This generates the lemma collection @{thm [source] lappend_simps}: |
|
1785 % |
|
1786 \[@{thm lappend_simps(1)[no_vars]} |
|
1787 \qquad @{thm lappend_simps(2)[no_vars]}\] |
|
1788 % |
1762 Corecursion is useful to specify not only functions but also infinite objects: |
1789 Corecursion is useful to specify not only functions but also infinite objects: |
1763 *} |
1790 *} |
1764 |
1791 |
1765 primcorec infty :: enat where |
1792 primcorec infty :: enat where |
1766 "infty = ESuc infty" |
1793 "infty = ESuc infty" |