109 |
109 |
110 code_datatype %quote AQueue |
110 code_datatype %quote AQueue |
111 |
111 |
112 text \<open> |
112 text \<open> |
113 \noindent Here we define a \qt{constructor} @{const "AQueue"} which |
113 \noindent Here we define a \qt{constructor} @{const "AQueue"} which |
114 is defined in terms of @{text "Queue"} and interprets its arguments |
114 is defined in terms of \<open>Queue\<close> and interprets its arguments |
115 according to what the \emph{content} of an amortised queue is supposed |
115 according to what the \emph{content} of an amortised queue is supposed |
116 to be. |
116 to be. |
117 |
117 |
118 The prerequisite for datatype constructors is only syntactical: a |
118 The prerequisite for datatype constructors is only syntactical: a |
119 constructor must be of type @{text "\<tau> = \<dots> \<Rightarrow> \<kappa> \<alpha>\<^sub>1 \<dots> \<alpha>\<^sub>n"} where @{text |
119 constructor must be of type \<open>\<tau> = \<dots> \<Rightarrow> \<kappa> \<alpha>\<^sub>1 \<dots> \<alpha>\<^sub>n\<close> where \<open>{\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n}\<close> is exactly the set of \emph{all} type variables in |
120 "{\<alpha>\<^sub>1, \<dots>, \<alpha>\<^sub>n}"} is exactly the set of \emph{all} type variables in |
120 \<open>\<tau>\<close>; then \<open>\<kappa>\<close> is its corresponding datatype. The |
121 @{text "\<tau>"}; then @{text "\<kappa>"} is its corresponding datatype. The |
|
122 HOL datatype package by default registers any new datatype with its |
121 HOL datatype package by default registers any new datatype with its |
123 constructors, but this may be changed using @{command_def |
122 constructors, but this may be changed using @{command_def |
124 code_datatype}; the currently chosen constructors can be inspected |
123 code_datatype}; the currently chosen constructors can be inspected |
125 using the @{command print_codesetup} command. |
124 using the @{command print_codesetup} command. |
126 |
125 |
225 set @{term "{xs. list_of_dlist (Dlist xs) = xs}"} are invariant, |
224 set @{term "{xs. list_of_dlist (Dlist xs) = xs}"} are invariant, |
226 and in our example this is exactly @{term "{xs. distinct xs}"}. |
225 and in our example this is exactly @{term "{xs. distinct xs}"}. |
227 |
226 |
228 The primitive operations on @{typ "'a dlist"} are specified |
227 The primitive operations on @{typ "'a dlist"} are specified |
229 indirectly using the projection @{const list_of_dlist}. For |
228 indirectly using the projection @{const list_of_dlist}. For |
230 the empty @{text "dlist"}, @{const Dlist.empty}, we finally want |
229 the empty \<open>dlist\<close>, @{const Dlist.empty}, we finally want |
231 the code equation |
230 the code equation |
232 \<close> |
231 \<close> |
233 |
232 |
234 text %quote \<open> |
233 text %quote \<open> |
235 @{term "Dlist.empty = Dlist []"} |
234 @{term "Dlist.empty = Dlist []"} |