doc-src/IsarAdvanced/Codegen/Thy/document/Codegen.tex
changeset 22845 5f9138bcb3d7
parent 22798 e3962371f568
child 22885 ebde66a71ab0
equal deleted inserted replaced
22844:91c05f4b509e 22845:5f9138bcb3d7
   170 \begin{isamarkuptext}%
   170 \begin{isamarkuptext}%
   171 \noindent Then we generate code%
   171 \noindent Then we generate code%
   172 \end{isamarkuptext}%
   172 \end{isamarkuptext}%
   173 \isamarkuptrue%
   173 \isamarkuptrue%
   174 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   174 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   175 \ example\ {\isacharparenleft}SML\ {\isachardoublequoteopen}examples{\isacharslash}tree{\isachardot}ML{\isachardoublequoteclose}{\isacharparenright}%
   175 \ example\ \isakeyword{in}\ SML\ \isakeyword{file}\ {\isachardoublequoteopen}examples{\isacharslash}tree{\isachardot}ML{\isachardoublequoteclose}%
   176 \begin{isamarkuptext}%
   176 \begin{isamarkuptext}%
   177 \noindent which looks like:
   177 \noindent which looks like:
   178   \lstsml{Thy/examples/tree.ML}%
   178   \lstsml{Thy/examples/tree.ML}%
   179 \end{isamarkuptext}%
   179 \end{isamarkuptext}%
   180 \isamarkuptrue%
   180 \isamarkuptrue%
   253 \begin{isamarkuptext}%
   253 \begin{isamarkuptext}%
   254 \noindent This executable specification is now turned to SML code:%
   254 \noindent This executable specification is now turned to SML code:%
   255 \end{isamarkuptext}%
   255 \end{isamarkuptext}%
   256 \isamarkuptrue%
   256 \isamarkuptrue%
   257 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   257 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   258 \ fac\ {\isacharparenleft}SML\ {\isachardoublequoteopen}examples{\isacharslash}fac{\isachardot}ML{\isachardoublequoteclose}{\isacharparenright}%
   258 \ fac\ \isakeyword{in}\ SML\ \isakeyword{file}\ {\isachardoublequoteopen}examples{\isacharslash}fac{\isachardot}ML{\isachardoublequoteclose}%
   259 \begin{isamarkuptext}%
   259 \begin{isamarkuptext}%
   260 \noindent  The \isa{{\isasymCODEGEN}} command takes a space-separated list of
   260 \noindent  The \isa{{\isasymCODEGEN}} command takes a space-separated list of
   261   constants together with \qn{serialization directives}
   261   constants together with \qn{serialization directives}
   262   in parentheses. These start with a \qn{target language}
   262   These start with a \qn{target language}
   263   identifier, followed by arguments, their semantics
   263   identifier, followed by a file specification
   264   depending on the target. In the SML case, a filename
   264   where to write the generated code to.
   265   is given where to write the generated code to.
       
   266 
   265 
   267   Internally, the defining equations for all selected
   266   Internally, the defining equations for all selected
   268   constants are taken, including any transitively required
   267   constants are taken, including any transitively required
   269   constants, datatypes and classes, resulting in the following
   268   constants, datatypes and classes, resulting in the following
   270   code:
   269   code:
   307 %
   306 %
   308 \isadelimML
   307 \isadelimML
   309 %
   308 %
   310 \endisadelimML
   309 \endisadelimML
   311 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   310 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   312 \ pick{\isacharunderscore}some\ {\isacharparenleft}SML\ {\isachardoublequoteopen}examples{\isacharslash}fail{\isacharunderscore}const{\isachardot}ML{\isachardoublequoteclose}{\isacharparenright}%
   311 \ pick{\isacharunderscore}some\ \isakeyword{in}\ SML\ \isakeyword{file}\ {\isachardoublequoteopen}examples{\isacharslash}fail{\isacharunderscore}const{\isachardot}ML{\isachardoublequoteclose}%
   313 \begin{isamarkuptext}%
   312 \begin{isamarkuptext}%
   314 \noindent will fail.%
   313 \noindent will fail.%
   315 \end{isamarkuptext}%
   314 \end{isamarkuptext}%
   316 \isamarkuptrue%
   315 \isamarkuptrue%
   317 %
   316 %
   372 \isanewline
   371 \isanewline
   373 %
   372 %
   374 \endisadelimproof
   373 \endisadelimproof
   375 \isanewline
   374 \isanewline
   376 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   375 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   377 \ pick\ {\isacharparenleft}SML\ {\isachardoublequoteopen}examples{\isacharslash}pick{\isadigit{1}}{\isachardot}ML{\isachardoublequoteclose}{\isacharparenright}%
   376 \ pick\ \ \isakeyword{in}\ SML\ \isakeyword{file}\ {\isachardoublequoteopen}examples{\isacharslash}pick{\isadigit{1}}{\isachardot}ML{\isachardoublequoteclose}%
   378 \begin{isamarkuptext}%
   377 \begin{isamarkuptext}%
   379 \noindent This theorem now is used for generating code:
   378 \noindent This theorem now is used for generating code:
   380 
   379 
   381   \lstsml{Thy/examples/pick1.ML}
   380   \lstsml{Thy/examples/pick1.ML}
   382 
   381 
   383   \noindent It might be convenient to remove the pointless original
   382   \noindent It might be convenient to remove the pointless original
   384   equation, using the \emph{nofunc} attribute:%
   383   equation, using the \emph{func del} attribute:%
   385 \end{isamarkuptext}%
   384 \end{isamarkuptext}%
   386 \isamarkuptrue%
   385 \isamarkuptrue%
   387 \isacommand{lemmas}\isamarkupfalse%
   386 \isacommand{lemmas}\isamarkupfalse%
   388 \ {\isacharbrackleft}code\ nofunc{\isacharbrackright}\ {\isacharequal}\ pick{\isachardot}simps\ \isanewline
   387 \ {\isacharbrackleft}code\ func\ del{\isacharbrackright}\ {\isacharequal}\ pick{\isachardot}simps\ \isanewline
   389 \isanewline
   388 \isanewline
   390 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   389 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   391 \ pick\ {\isacharparenleft}SML\ {\isachardoublequoteopen}examples{\isacharslash}pick{\isadigit{2}}{\isachardot}ML{\isachardoublequoteclose}{\isacharparenright}%
   390 \ pick\ \ \isakeyword{in}\ SML\ \isakeyword{file}\ {\isachardoublequoteopen}examples{\isacharslash}pick{\isadigit{2}}{\isachardot}ML{\isachardoublequoteclose}%
   392 \begin{isamarkuptext}%
   391 \begin{isamarkuptext}%
   393 \lstsml{Thy/examples/pick2.ML}
   392 \lstsml{Thy/examples/pick2.ML}
   394 
   393 
   395   \noindent Syntactic redundancies are implicitly dropped. For example,
   394   \noindent Syntactic redundancies are implicitly dropped. For example,
   396   using a modified version of the \isa{fac} function
   395   using a modified version of the \isa{fac} function
   417 \isanewline
   416 \isanewline
   418 %
   417 %
   419 \endisadelimproof
   418 \endisadelimproof
   420 \isanewline
   419 \isanewline
   421 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   420 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   422 \ fac\ {\isacharparenleft}SML\ {\isachardoublequoteopen}examples{\isacharslash}fac{\isacharunderscore}case{\isachardot}ML{\isachardoublequoteclose}{\isacharparenright}%
   421 \ fac\ \isakeyword{in}\ SML\ \isakeyword{file}\ {\isachardoublequoteopen}examples{\isacharslash}fac{\isacharunderscore}case{\isachardot}ML{\isachardoublequoteclose}%
   423 \begin{isamarkuptext}%
   422 \begin{isamarkuptext}%
   424 \lstsml{Thy/examples/fac_case.ML}
   423 \lstsml{Thy/examples/fac_case.ML}
   425 
   424 
   426   \begin{warn}
   425   \begin{warn}
   427     The attributes \emph{code} and \emph{code del}
   426     The attributes \emph{code} and \emph{code del}
   428     associated with the existing code generator also apply to
   427     associated with the existing code generator also apply to
   429     the new one: \emph{code} implies \emph{code func},
   428     the new one: \emph{code} implies \emph{code func},
   430     and \emph{code del} implies \emph{code nofunc}.
   429     and \emph{code del} implies \emph{code func del}.
   431   \end{warn}%
   430   \end{warn}%
   432 \end{isamarkuptext}%
   431 \end{isamarkuptext}%
   433 \isamarkuptrue%
   432 \isamarkuptrue%
   434 %
   433 %
   435 \isamarkupsubsection{Type classes%
   434 \isamarkupsubsection{Type classes%
   508 Type classes offer a suitable occasion to introduce
   507 Type classes offer a suitable occasion to introduce
   509   the Haskell serializer.  Its usage is almost the same
   508   the Haskell serializer.  Its usage is almost the same
   510   as SML, but, in accordance with conventions
   509   as SML, but, in accordance with conventions
   511   some Haskell systems enforce, each module ends
   510   some Haskell systems enforce, each module ends
   512   up in a single file. The module hierarchy is reflected in
   511   up in a single file. The module hierarchy is reflected in
   513   the file system, with root given by the user.%
   512   the file system, with root directory given as file specification.%
   514 \end{isamarkuptext}%
   513 \end{isamarkuptext}%
   515 \isamarkuptrue%
   514 \isamarkuptrue%
   516 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   515 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   517 \ dummy\ {\isacharparenleft}Haskell\ {\isachardoublequoteopen}examples{\isacharslash}{\isachardoublequoteclose}{\isacharparenright}%
   516 \ dummy\ \isakeyword{in}\ Haskell\ \isakeyword{file}\ {\isachardoublequoteopen}examples{\isacharslash}{\isachardoublequoteclose}%
   518 \begin{isamarkuptext}%
   517 \begin{isamarkuptext}%
   519 \lsthaskell{Thy/examples/Codegen.hs}
   518 \lsthaskell{Thy/examples/Codegen.hs}
   520   \noindent (we have left out all other modules).
   519   \noindent (we have left out all other modules).
   521 
   520 
   522   \medskip
   521   \medskip
   523 
   522 
   524   The whole code in SML with explicit dictionary passing:%
   523   The whole code in SML with explicit dictionary passing:%
   525 \end{isamarkuptext}%
   524 \end{isamarkuptext}%
   526 \isamarkuptrue%
   525 \isamarkuptrue%
   527 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   526 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   528 \ dummy\ {\isacharparenleft}SML\ {\isachardoublequoteopen}examples{\isacharslash}class{\isachardot}ML{\isachardoublequoteclose}{\isacharparenright}%
   527 \ dummy\ \isakeyword{in}\ SML\ \isakeyword{file}\ {\isachardoublequoteopen}examples{\isacharslash}class{\isachardot}ML{\isachardoublequoteclose}%
   529 \begin{isamarkuptext}%
   528 \begin{isamarkuptext}%
   530 \lstsml{Thy/examples/class.ML}
   529 \lstsml{Thy/examples/class.ML}
   531 
   530 
   532   \medskip
   531   \medskip
   533 
   532 
   534   \noindent or in OCaml:%
   533   \noindent or in OCaml:%
   535 \end{isamarkuptext}%
   534 \end{isamarkuptext}%
   536 \isamarkuptrue%
   535 \isamarkuptrue%
   537 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   536 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   538 \ dummy\ {\isacharparenleft}OCaml\ {\isachardoublequoteopen}examples{\isacharslash}class{\isachardot}ocaml{\isachardoublequoteclose}{\isacharparenright}%
   537 \ dummy\ \isakeyword{in}\ OCaml\ \isakeyword{file}\ {\isachardoublequoteopen}examples{\isacharslash}class{\isachardot}ocaml{\isachardoublequoteclose}%
   539 \begin{isamarkuptext}%
   538 \begin{isamarkuptext}%
   540 \lstsml{Thy/examples/class.ocaml}
   539 \lstsml{Thy/examples/class.ocaml}
   541 
   540 
   542   \medskip The explicit association of constants
   541   \medskip The explicit association of constants
   543   to classes can be inspected using the \isa{{\isasymPRINTCLASSES}}%
   542   to classes can be inspected using the \isa{{\isasymPRINTCLASSES}}
       
   543   command.%
   544 \end{isamarkuptext}%
   544 \end{isamarkuptext}%
   545 \isamarkuptrue%
   545 \isamarkuptrue%
   546 %
   546 %
   547 \isamarkupsection{Recipes and advanced topics \label{sec:advanced}%
   547 \isamarkupsection{Recipes and advanced topics \label{sec:advanced}%
   548 }
   548 }
   618   defining equation.  Due to the interpretation of theorems
   618   defining equation.  Due to the interpretation of theorems
   619   of defining equations, rewrites are applied to the right
   619   of defining equations, rewrites are applied to the right
   620   hand side and the arguments of the left hand side of an
   620   hand side and the arguments of the left hand side of an
   621   equation, but never to the constant heading the left hand side.
   621   equation, but never to the constant heading the left hand side.
   622   Inline theorems may be declared an undeclared using the
   622   Inline theorems may be declared an undeclared using the
   623   \emph{code inline} or \emph{code noinline} attribute respectively.
   623   \emph{code inline} or \emph{code inline del} attribute respectively.
   624   Some common applications:%
   624   Some common applications:%
   625 \end{isamarkuptext}%
   625 \end{isamarkuptext}%
   626 \isamarkuptrue%
   626 \isamarkuptrue%
   627 %
   627 %
   628 \begin{itemize}
   628 \begin{itemize}
   629      \item replacing non-executable constructs by executable ones: \\
   629 %
   630 \isacommand{lemma}\isamarkupfalse%
   630 \begin{isamarkuptext}%
       
   631 \item replacing non-executable constructs by executable ones:%
       
   632 \end{isamarkuptext}%
       
   633 \isamarkuptrue%
       
   634 \ \ \isacommand{lemma}\isamarkupfalse%
   631 \ {\isacharbrackleft}code\ inline{\isacharbrackright}{\isacharcolon}\isanewline
   635 \ {\isacharbrackleft}code\ inline{\isacharbrackright}{\isacharcolon}\isanewline
   632 \ \ {\isachardoublequoteopen}x\ {\isasymin}\ set\ xs\ {\isasymlongleftrightarrow}\ x\ mem\ xs{\isachardoublequoteclose}%
   636 \ \ \ \ {\isachardoublequoteopen}x\ {\isasymin}\ set\ xs\ {\isasymlongleftrightarrow}\ x\ mem\ xs{\isachardoublequoteclose}%
   633 \isadelimproof
   637 \isadelimproof
   634 \ %
   638 \ %
   635 \endisadelimproof
   639 \endisadelimproof
   636 %
   640 %
   637 \isatagproof
   641 \isatagproof
   642 %
   646 %
   643 \isadelimproof
   647 \isadelimproof
   644 %
   648 %
   645 \endisadelimproof
   649 \endisadelimproof
   646 %
   650 %
   647 \item eliminating superfluous constants: \\
   651 \begin{isamarkuptext}%
   648 \isacommand{lemma}\isamarkupfalse%
   652 \item eliminating superfluous constants:%
       
   653 \end{isamarkuptext}%
       
   654 \isamarkuptrue%
       
   655 \ \ \isacommand{lemma}\isamarkupfalse%
   649 \ {\isacharbrackleft}code\ inline{\isacharbrackright}{\isacharcolon}\isanewline
   656 \ {\isacharbrackleft}code\ inline{\isacharbrackright}{\isacharcolon}\isanewline
   650 \ \ {\isachardoublequoteopen}{\isadigit{1}}\ {\isacharequal}\ Suc\ {\isadigit{0}}{\isachardoublequoteclose}%
   657 \ \ \ \ {\isachardoublequoteopen}{\isadigit{1}}\ {\isacharequal}\ Suc\ {\isadigit{0}}{\isachardoublequoteclose}%
   651 \isadelimproof
   658 \isadelimproof
   652 \ %
   659 \ %
   653 \endisadelimproof
   660 \endisadelimproof
   654 %
   661 %
   655 \isatagproof
   662 \isatagproof
   660 %
   667 %
   661 \isadelimproof
   668 \isadelimproof
   662 %
   669 %
   663 \endisadelimproof
   670 \endisadelimproof
   664 %
   671 %
   665 \item replacing executable but inconvenient constructs: \\
   672 \begin{isamarkuptext}%
   666 \isacommand{lemma}\isamarkupfalse%
   673 \item replacing executable but inconvenient constructs:%
       
   674 \end{isamarkuptext}%
       
   675 \isamarkuptrue%
       
   676 \ \ \isacommand{lemma}\isamarkupfalse%
   667 \ {\isacharbrackleft}code\ inline{\isacharbrackright}{\isacharcolon}\isanewline
   677 \ {\isacharbrackleft}code\ inline{\isacharbrackright}{\isacharcolon}\isanewline
   668 \ \ {\isachardoublequoteopen}xs\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}\ {\isasymlongleftrightarrow}\ List{\isachardot}null\ xs{\isachardoublequoteclose}%
   678 \ \ \ \ {\isachardoublequoteopen}xs\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}\ {\isasymlongleftrightarrow}\ List{\isachardot}null\ xs{\isachardoublequoteclose}%
   669 \isadelimproof
   679 \isadelimproof
   670 \ %
   680 \ %
   671 \endisadelimproof
   681 \endisadelimproof
   672 %
   682 %
   673 \isatagproof
   683 \isatagproof
   681 \endisadelimproof
   691 \endisadelimproof
   682 %
   692 %
   683 \end{itemize}
   693 \end{itemize}
   684 %
   694 %
   685 \begin{isamarkuptext}%
   695 \begin{isamarkuptext}%
   686 The current set of inline theorems may be inspected using
   696 \noindent The current set of inline theorems may be inspected using
   687   the \isa{{\isasymPRINTCODESETUP}} command.
   697   the \isa{{\isasymPRINTCODESETUP}} command.
   688 
   698 
   689   \emph{Inline procedures} are a generalized version of inline
   699   \emph{Inline procedures} are a generalized version of inline
   690   theorems written in ML -- rewrite rules are generated dependent
   700   theorems written in ML -- rewrite rules are generated dependent
   691   on the function theorems for a certain function.  One
   701   on the function theorems for a certain function.  One
   737   resulting in \isa{op\ mem}, which itself
   747   resulting in \isa{op\ mem}, which itself
   738   performs an explicit equality check.%
   748   performs an explicit equality check.%
   739 \end{isamarkuptext}%
   749 \end{isamarkuptext}%
   740 \isamarkuptrue%
   750 \isamarkuptrue%
   741 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   751 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   742 \ collect{\isacharunderscore}duplicates\ {\isacharparenleft}SML\ {\isachardoublequoteopen}examples{\isacharslash}collect{\isacharunderscore}duplicates{\isachardot}ML{\isachardoublequoteclose}{\isacharparenright}%
   752 \ collect{\isacharunderscore}duplicates\ \isakeyword{in}\ SML\ \isakeyword{file}\ {\isachardoublequoteopen}examples{\isacharslash}collect{\isacharunderscore}duplicates{\isachardot}ML{\isachardoublequoteclose}%
   743 \begin{isamarkuptext}%
   753 \begin{isamarkuptext}%
   744 \lstsml{Thy/examples/collect_duplicates.ML}%
   754 \lstsml{Thy/examples/collect_duplicates.ML}%
   745 \end{isamarkuptext}%
   755 \end{isamarkuptext}%
   746 \isamarkuptrue%
   756 \isamarkuptrue%
   747 %
   757 %
   815 %
   825 %
   816 \endisadelimproof
   826 \endisadelimproof
   817 \isanewline
   827 \isanewline
   818 \isanewline
   828 \isanewline
   819 \isacommand{lemmas}\isamarkupfalse%
   829 \isacommand{lemmas}\isamarkupfalse%
   820 \ {\isacharbrackleft}code\ nofunc{\isacharbrackright}\ {\isacharequal}\ less{\isacharunderscore}prod{\isacharunderscore}def\ less{\isacharunderscore}eq{\isacharunderscore}prod{\isacharunderscore}def\isanewline
   830 \ {\isacharbrackleft}code\ func\ del{\isacharbrackright}\ {\isacharequal}\ less{\isacharunderscore}prod{\isacharunderscore}def\ less{\isacharunderscore}eq{\isacharunderscore}prod{\isacharunderscore}def\isanewline
   821 \isanewline
   831 \isanewline
   822 \isacommand{lemma}\isamarkupfalse%
   832 \isacommand{lemma}\isamarkupfalse%
   823 \ ord{\isacharunderscore}prod\ {\isacharbrackleft}code\ func{\isacharbrackright}{\isacharcolon}\isanewline
   833 \ ord{\isacharunderscore}prod\ {\isacharbrackleft}code\ func{\isacharbrackright}{\isacharcolon}\isanewline
   824 \ \ {\isachardoublequoteopen}{\isacharparenleft}x{\isadigit{1}}\ {\isasymColon}\ {\isacharprime}a{\isasymColon}ord{\isacharcomma}\ y{\isadigit{1}}\ {\isasymColon}\ {\isacharprime}b{\isasymColon}ord{\isacharparenright}\ {\isacharless}\ {\isacharparenleft}x{\isadigit{2}}{\isacharcomma}\ y{\isadigit{2}}{\isacharparenright}\ {\isasymlongleftrightarrow}\ x{\isadigit{1}}\ {\isacharless}\ x{\isadigit{2}}\ {\isasymor}\ {\isacharparenleft}x{\isadigit{1}}\ {\isacharequal}\ x{\isadigit{2}}\ {\isasymand}\ y{\isadigit{1}}\ {\isacharless}\ y{\isadigit{2}}{\isacharparenright}{\isachardoublequoteclose}\isanewline
   834 \ \ {\isachardoublequoteopen}{\isacharparenleft}x{\isadigit{1}}\ {\isasymColon}\ {\isacharprime}a{\isasymColon}ord{\isacharcomma}\ y{\isadigit{1}}\ {\isasymColon}\ {\isacharprime}b{\isasymColon}ord{\isacharparenright}\ {\isacharless}\ {\isacharparenleft}x{\isadigit{2}}{\isacharcomma}\ y{\isadigit{2}}{\isacharparenright}\ {\isasymlongleftrightarrow}\ x{\isadigit{1}}\ {\isacharless}\ x{\isadigit{2}}\ {\isasymor}\ {\isacharparenleft}x{\isadigit{1}}\ {\isacharequal}\ x{\isadigit{2}}\ {\isasymand}\ y{\isadigit{1}}\ {\isacharless}\ y{\isadigit{2}}{\isacharparenright}{\isachardoublequoteclose}\isanewline
   825 \ \ {\isachardoublequoteopen}{\isacharparenleft}x{\isadigit{1}}\ {\isasymColon}\ {\isacharprime}a{\isasymColon}ord{\isacharcomma}\ y{\isadigit{1}}\ {\isasymColon}\ {\isacharprime}b{\isasymColon}ord{\isacharparenright}\ {\isasymle}\ {\isacharparenleft}x{\isadigit{2}}{\isacharcomma}\ y{\isadigit{2}}{\isacharparenright}\ {\isasymlongleftrightarrow}\ x{\isadigit{1}}\ {\isacharless}\ x{\isadigit{2}}\ {\isasymor}\ {\isacharparenleft}x{\isadigit{1}}\ {\isacharequal}\ x{\isadigit{2}}\ {\isasymand}\ y{\isadigit{1}}\ {\isasymle}\ y{\isadigit{2}}{\isacharparenright}{\isachardoublequoteclose}\isanewline
   835 \ \ {\isachardoublequoteopen}{\isacharparenleft}x{\isadigit{1}}\ {\isasymColon}\ {\isacharprime}a{\isasymColon}ord{\isacharcomma}\ y{\isadigit{1}}\ {\isasymColon}\ {\isacharprime}b{\isasymColon}ord{\isacharparenright}\ {\isasymle}\ {\isacharparenleft}x{\isadigit{2}}{\isacharcomma}\ y{\isadigit{2}}{\isacharparenright}\ {\isasymlongleftrightarrow}\ x{\isadigit{1}}\ {\isacharless}\ x{\isadigit{2}}\ {\isasymor}\ {\isacharparenleft}x{\isadigit{1}}\ {\isacharequal}\ x{\isadigit{2}}\ {\isasymand}\ y{\isadigit{1}}\ {\isasymle}\ y{\isadigit{2}}{\isacharparenright}{\isachardoublequoteclose}\isanewline
   876 \noindent Then code generation succeeds:%
   886 \noindent Then code generation succeeds:%
   877 \end{isamarkuptext}%
   887 \end{isamarkuptext}%
   878 \isamarkuptrue%
   888 \isamarkuptrue%
   879 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   889 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   880 \ {\isachardoublequoteopen}op\ {\isasymle}\ {\isasymColon}\ {\isacharprime}a{\isasymColon}{\isacharbraceleft}eq{\isacharcomma}\ ord{\isacharbraceright}\ {\isasymtimes}\ {\isacharprime}b{\isasymColon}ord\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymtimes}\ {\isacharprime}b\ {\isasymRightarrow}\ bool{\isachardoublequoteclose}\isanewline
   890 \ {\isachardoublequoteopen}op\ {\isasymle}\ {\isasymColon}\ {\isacharprime}a{\isasymColon}{\isacharbraceleft}eq{\isacharcomma}\ ord{\isacharbraceright}\ {\isasymtimes}\ {\isacharprime}b{\isasymColon}ord\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymtimes}\ {\isacharprime}b\ {\isasymRightarrow}\ bool{\isachardoublequoteclose}\isanewline
   881 \ \ {\isacharparenleft}SML\ {\isachardoublequoteopen}examples{\isacharslash}lexicographic{\isachardot}ML{\isachardoublequoteclose}{\isacharparenright}%
   891 \ \ \isakeyword{in}\ SML\ \isakeyword{file}\ {\isachardoublequoteopen}examples{\isacharslash}lexicographic{\isachardot}ML{\isachardoublequoteclose}%
   882 \begin{isamarkuptext}%
   892 \begin{isamarkuptext}%
   883 \lstsml{Thy/examples/lexicographic.ML}%
   893 \lstsml{Thy/examples/lexicographic.ML}%
   884 \end{isamarkuptext}%
   894 \end{isamarkuptext}%
   885 \isamarkuptrue%
   895 \isamarkuptrue%
   886 %
   896 %
   950 %
   960 %
   951 \isadelimtt
   961 \isadelimtt
   952 %
   962 %
   953 \endisadelimtt
   963 \endisadelimtt
   954 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   964 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   955 \ in{\isacharunderscore}interval\ {\isacharparenleft}SML\ {\isachardoublequoteopen}examples{\isacharslash}bool{\isacharunderscore}literal{\isachardot}ML{\isachardoublequoteclose}{\isacharparenright}%
   965 \ in{\isacharunderscore}interval\ \isakeyword{in}\ SML\ \isakeyword{file}\ {\isachardoublequoteopen}examples{\isacharslash}bool{\isacharunderscore}literal{\isachardot}ML{\isachardoublequoteclose}%
   956 \begin{isamarkuptext}%
   966 \begin{isamarkuptext}%
   957 \lstsml{Thy/examples/bool_literal.ML}
   967 \lstsml{Thy/examples/bool_literal.ML}
   958 
   968 
   959   \noindent Though this is correct code, it is a little bit unsatisfactory:
   969   \noindent Though this is correct code, it is a little bit unsatisfactory:
   960   boolean values and operators are materialized as distinguished
   970   boolean values and operators are materialized as distinguished
  1007 
  1017 
  1008   After this setup, code looks quite more readable:%
  1018   After this setup, code looks quite more readable:%
  1009 \end{isamarkuptext}%
  1019 \end{isamarkuptext}%
  1010 \isamarkuptrue%
  1020 \isamarkuptrue%
  1011 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
  1021 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
  1012 \ in{\isacharunderscore}interval\ {\isacharparenleft}SML\ {\isachardoublequoteopen}examples{\isacharslash}bool{\isacharunderscore}mlbool{\isachardot}ML{\isachardoublequoteclose}{\isacharparenright}%
  1022 \ in{\isacharunderscore}interval\ \ \isakeyword{in}\ SML\ \isakeyword{file}\ {\isachardoublequoteopen}examples{\isacharslash}bool{\isacharunderscore}mlbool{\isachardot}ML{\isachardoublequoteclose}%
  1013 \begin{isamarkuptext}%
  1023 \begin{isamarkuptext}%
  1014 \lstsml{Thy/examples/bool_mlbool.ML}
  1024 \lstsml{Thy/examples/bool_mlbool.ML}
  1015 
  1025 
  1016   \noindent This still is not perfect: the parentheses
  1026   \noindent This still is not perfect: the parentheses
  1017   around the \qt{andalso} expression are superfluous.
  1027   around the \qt{andalso} expression are superfluous.
  1037 %
  1047 %
  1038 \endisadelimtt
  1048 \endisadelimtt
  1039 \isanewline
  1049 \isanewline
  1040 \isanewline
  1050 \isanewline
  1041 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
  1051 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
  1042 \ in{\isacharunderscore}interval\ {\isacharparenleft}SML\ {\isachardoublequoteopen}examples{\isacharslash}bool{\isacharunderscore}infix{\isachardot}ML{\isachardoublequoteclose}{\isacharparenright}%
  1052 \ in{\isacharunderscore}interval\ \ \isakeyword{in}\ SML\ \isakeyword{file}\ {\isachardoublequoteopen}examples{\isacharslash}bool{\isacharunderscore}infix{\isachardot}ML{\isachardoublequoteclose}%
  1043 \begin{isamarkuptext}%
  1053 \begin{isamarkuptext}%
  1044 \lstsml{Thy/examples/bool_infix.ML}
  1054 \lstsml{Thy/examples/bool_infix.ML}
  1045 
  1055 
  1046   \medskip
  1056   \medskip
  1047 
  1057 
  1313 %
  1323 %
  1314 \endisadelimproof
  1324 \endisadelimproof
  1315 \isanewline
  1325 \isanewline
  1316 \isanewline
  1326 \isanewline
  1317 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
  1327 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
  1318 \ {\isachardoublequoteopen}{\isacharbraceleft}{\isacharbraceright}{\isachardoublequoteclose}\ insert\ {\isachardoublequoteopen}op\ {\isasymin}{\isachardoublequoteclose}\ {\isachardoublequoteopen}op\ {\isasymunion}{\isachardoublequoteclose}\ {\isachardoublequoteopen}Union{\isachardoublequoteclose}\ {\isacharparenleft}SML\ {\isachardoublequoteopen}examples{\isacharslash}set{\isacharunderscore}list{\isachardot}ML{\isachardoublequoteclose}{\isacharparenright}%
  1328 \ {\isachardoublequoteopen}{\isacharbraceleft}{\isacharbraceright}{\isachardoublequoteclose}\ insert\ {\isachardoublequoteopen}op\ {\isasymin}{\isachardoublequoteclose}\ {\isachardoublequoteopen}op\ {\isasymunion}{\isachardoublequoteclose}\ {\isachardoublequoteopen}Union{\isachardoublequoteclose}\ \ \isakeyword{in}\ SML\ \isakeyword{file}\ {\isachardoublequoteopen}examples{\isacharslash}set{\isacharunderscore}list{\isachardot}ML{\isachardoublequoteclose}%
  1319 \begin{isamarkuptext}%
  1329 \begin{isamarkuptext}%
  1320 \lstsml{Thy/examples/set_list.ML}
  1330 \lstsml{Thy/examples/set_list.ML}
  1321 
  1331 
  1322   \medskip
  1332   \medskip
  1323 
  1333 
  1447 \ \ dummy{\isacharunderscore}option\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ list\ {\isasymRightarrow}\ {\isacharprime}a\ option{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
  1457 \ \ dummy{\isacharunderscore}option\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ list\ {\isasymRightarrow}\ {\isacharprime}a\ option{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
  1448 \ \ \ \ {\isachardoublequoteopen}dummy{\isacharunderscore}option\ {\isacharparenleft}x{\isacharhash}xs{\isacharparenright}\ {\isacharequal}\ Some\ x{\isachardoublequoteclose}\isanewline
  1458 \ \ \ \ {\isachardoublequoteopen}dummy{\isacharunderscore}option\ {\isacharparenleft}x{\isacharhash}xs{\isacharparenright}\ {\isacharequal}\ Some\ x{\isachardoublequoteclose}\isanewline
  1449 \ \ {\isacharbar}\ {\isachardoublequoteopen}dummy{\isacharunderscore}option\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharequal}\ arbitrary{\isachardoublequoteclose}\isanewline
  1459 \ \ {\isacharbar}\ {\isachardoublequoteopen}dummy{\isacharunderscore}option\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharequal}\ arbitrary{\isachardoublequoteclose}\isanewline
  1450 \isanewline
  1460 \isanewline
  1451 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
  1461 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
  1452 \ dummy{\isacharunderscore}option\ {\isacharparenleft}SML\ {\isachardoublequoteopen}examples{\isacharslash}arbitrary{\isachardot}ML{\isachardoublequoteclose}{\isacharparenright}%
  1462 \ dummy{\isacharunderscore}option\ \isakeyword{in}\ SML\ \isakeyword{file}\ {\isachardoublequoteopen}examples{\isacharslash}arbitrary{\isachardot}ML{\isachardoublequoteclose}%
  1453 \begin{isamarkuptext}%
  1463 \begin{isamarkuptext}%
  1454 \lstsml{Thy/examples/arbitrary.ML}
  1464 \lstsml{Thy/examples/arbitrary.ML}
  1455 
  1465 
  1456   \medskip
  1466   \medskip
  1457 
  1467