equal
deleted
inserted
replaced
9 text {* |
9 text {* |
10 We have already seen how by default equations stemming from |
10 We have already seen how by default equations stemming from |
11 @{command definition}/@{command primrec}/@{command fun} |
11 @{command definition}/@{command primrec}/@{command fun} |
12 statements are used for code generation. This default behaviour |
12 statements are used for code generation. This default behaviour |
13 can be changed, e.g. by providing different defining equations. |
13 can be changed, e.g. by providing different defining equations. |
14 All kinds of customization shown in this section is \emph{safe} |
14 All kinds of customisation shown in this section is \emph{safe} |
15 in the sense that the user does not have to worry about |
15 in the sense that the user does not have to worry about |
16 correctness -- all programs generatable that way are partially |
16 correctness -- all programs generatable that way are partially |
17 correct. |
17 correct. |
18 *} |
18 *} |
19 |
19 |
220 subsection {* Datatypes \label{sec:datatypes} *} |
220 subsection {* Datatypes \label{sec:datatypes} *} |
221 |
221 |
222 text {* |
222 text {* |
223 Conceptually, any datatype is spanned by a set of |
223 Conceptually, any datatype is spanned by a set of |
224 \emph{constructors} of type @{text "\<tau> = \<dots> \<Rightarrow> \<kappa> \<alpha>\<^isub>1 \<dots> \<alpha>\<^isub>n"} |
224 \emph{constructors} of type @{text "\<tau> = \<dots> \<Rightarrow> \<kappa> \<alpha>\<^isub>1 \<dots> \<alpha>\<^isub>n"} |
225 where @{text "{\<alpha>\<^isub>1, \<dots>, \<alpha>\<^isub>n}"} is excactly the set of \emph{all} |
225 where @{text "{\<alpha>\<^isub>1, \<dots>, \<alpha>\<^isub>n}"} is exactly the set of \emph{all} |
226 type variables in @{text "\<tau>"}. The HOL datatype package |
226 type variables in @{text "\<tau>"}. The HOL datatype package |
227 by default registers any new datatype in the table |
227 by default registers any new datatype in the table |
228 of datatypes, which may be inspected using |
228 of datatypes, which may be inspected using |
229 the @{command print_codesetup} command. |
229 the @{command print_codesetup} command. |
230 |
230 |
429 that the generated code contains illegal mutual dependencies: |
429 that the generated code contains illegal mutual dependencies: |
430 the theorem @{thm monotype_eq [no_vars]} already requires the |
430 the theorem @{thm monotype_eq [no_vars]} already requires the |
431 instance @{text "monotype \<Colon> eq"}, which itself requires |
431 instance @{text "monotype \<Colon> eq"}, which itself requires |
432 @{thm monotype_eq [no_vars]}; Haskell has no problem with mutually |
432 @{thm monotype_eq [no_vars]}; Haskell has no problem with mutually |
433 recursive @{text instance} and @{text function} definitions, |
433 recursive @{text instance} and @{text function} definitions, |
434 but the SML serializer does not support this. |
434 but the SML serialiser does not support this. |
435 |
435 |
436 In such cases, you have to provide your own equality equations |
436 In such cases, you have to provide your own equality equations |
437 involving auxiliary constants. In our case, |
437 involving auxiliary constants. In our case, |
438 @{const [show_types] list_all2} can do the job: |
438 @{const [show_types] list_all2} can do the job: |
439 *} |
439 *} |
496 Normally, if constants without any defining equations occur in |
496 Normally, if constants without any defining equations occur in |
497 a program, the code generator complains (since in most cases |
497 a program, the code generator complains (since in most cases |
498 this is not what the user expects). But such constants can also |
498 this is not what the user expects). But such constants can also |
499 be thought of as function definitions with no equations which |
499 be thought of as function definitions with no equations which |
500 always fail, since there is never a successful pattern match |
500 always fail, since there is never a successful pattern match |
501 on the left hand side. In order to categorize a constant into |
501 on the left hand side. In order to categorise a constant into |
502 that category explicitly, use @{command "code_abort"}: |
502 that category explicitly, use @{command "code_abort"}: |
503 *} |
503 *} |
504 |
504 |
505 code_abort %quote empty_queue |
505 code_abort %quote empty_queue |
506 |
506 |