doc-src/Codegen/Thy/document/Foundations.tex
author bulwahn
Tue, 08 May 2012 14:31:03 +0200
changeset 47893 4cf901b1089a
parent 46563 0ad69b30b39c
permissions -rw-r--r--
specialised fact in the Record theory should not be appear in proofs discovered by sledgehammer
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
     1
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
     2
\begin{isabellebody}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
     3
\def\isabellecontext{Foundations}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
     4
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
     5
\isadelimtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
     6
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
     7
\endisadelimtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
     8
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
     9
\isatagtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    10
\isacommand{theory}\isamarkupfalse%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    11
\ Foundations\isanewline
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    12
\isakeyword{imports}\ Introduction\isanewline
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    13
\isakeyword{begin}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    14
\endisatagtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    15
{\isafoldtheory}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    16
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    17
\isadelimtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    18
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    19
\endisadelimtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    20
%
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    21
\isamarkupsection{Code generation foundations \label{sec:foundations}%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    22
}
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    23
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    24
%
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    25
\isamarkupsubsection{Code generator architecture \label{sec:architecture}%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    26
}
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    27
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    28
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    29
\begin{isamarkuptext}%
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    30
The code generator is actually a framework consisting of different
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    31
  components which can be customised individually.
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    32
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    33
  Conceptually all components operate on Isabelle's logic framework
46563
0ad69b30b39c updated generated files (cf. 8d51b375e926);
wenzelm
parents: 46523
diff changeset
    34
  \isa{Pure}.  Practically, the object logic \isa{HOL}
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    35
  provides the necessary facilities to make use of the code generator,
46563
0ad69b30b39c updated generated files (cf. 8d51b375e926);
wenzelm
parents: 46523
diff changeset
    36
  mainly since it is an extension of \isa{Pure}.
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    37
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    38
  The constellation of the different components is visualized in the
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    39
  following picture.
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    40
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    41
  \begin{figure}[h]
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    42
    \includegraphics{architecture}
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    43
    \caption{Code generator architecture}
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    44
    \label{fig:arch}
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    45
  \end{figure}
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    46
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    47
  \noindent Central to code generation is the notion of \emph{code
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    48
  equations}.  A code equation as a first approximation is a theorem
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
    49
  of the form \isa{f\ t\isaliteral{5C3C5E697375623E}{}\isactrlisub {\isadigit{1}}\ t\isaliteral{5C3C5E697375623E}{}\isactrlisub {\isadigit{2}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ t\isaliteral{5C3C5E697375623E}{}\isactrlisub n\ {\isaliteral{5C3C65717569763E}{\isasymequiv}}\ t} (an equation headed by a
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
    50
  constant \isa{f} with arguments \isa{t\isaliteral{5C3C5E697375623E}{}\isactrlisub {\isadigit{1}}\ t\isaliteral{5C3C5E697375623E}{}\isactrlisub {\isadigit{2}}\ {\isaliteral{5C3C646F74733E}{\isasymdots}}\ t\isaliteral{5C3C5E697375623E}{}\isactrlisub n} and right
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    51
  hand side \isa{t}).
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    52
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    53
  \begin{itemize}
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    54
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    55
    \item Starting point of code generation is a collection of (raw)
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    56
      code equations in a theory. It is not relevant where they stem
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    57
      from, but typically they were either produced by specification
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    58
      tools or proved explicitly by the user.
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    59
      
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    60
    \item These raw code equations can be subjected to theorem
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    61
      transformations.  This \qn{preprocessor} (see
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    62
      \secref{sec:preproc}) can apply the full expressiveness of
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    63
      ML-based theorem transformations to code generation.  The result
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    64
      of preprocessing is a structured collection of code equations.
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    65
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    66
    \item These code equations are \qn{translated} to a program in an
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    67
      abstract intermediate language.  Think of it as a kind of
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    68
      \qt{Mini-Haskell} with four \qn{statements}: \isa{data} (for
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    69
      datatypes), \isa{fun} (stemming from code equations), also
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    70
      \isa{class} and \isa{inst} (for type classes).
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    71
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    72
    \item Finally, the abstract program is \qn{serialised} into
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    73
      concrete source code of a target language.  This step only
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    74
      produces concrete syntax but does not change the program in
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    75
      essence; all conceptual transformations occur in the translation
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    76
      step.
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    77
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    78
  \end{itemize}
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    79
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    80
  \noindent From these steps, only the last two are carried out
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    81
  outside the logic; by keeping this layer as thin as possible, the
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    82
  amount of code to trust is kept to a minimum.%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    83
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    84
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    85
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    86
\isamarkupsubsection{The preprocessor \label{sec:preproc}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    87
}
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    88
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    89
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    90
\begin{isamarkuptext}%
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    91
Before selected function theorems are turned into abstract code, a
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    92
  chain of definitional transformation steps is carried out:
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    93
  \emph{preprocessing}.  The preprocessor consists of two
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    94
  components: a \emph{simpset} and \emph{function transformers}.
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    95
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    96
  The \emph{simpset} can apply the full generality of the Isabelle
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    97
  simplifier.  Due to the interpretation of theorems as code
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    98
  equations, rewrites are applied to the right hand side and the
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
    99
  arguments of the left hand side of an equation, but never to the
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   100
  constant heading the left hand side.  An important special case are
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   101
  \emph{unfold theorems}, which may be declared and removed using the
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   102
  \hyperlink{attribute.code-unfold}{\mbox{\isa{code{\isaliteral{5F}{\isacharunderscore}}unfold}}} or \emph{\hyperlink{attribute.code-unfold}{\mbox{\isa{code{\isaliteral{5F}{\isacharunderscore}}unfold}}} del}
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   103
  attribute, respectively.
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   104
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   105
  Some common applications:%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   106
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   107
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   108
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   109
\begin{itemize}
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   110
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   111
\begin{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   112
\item replacing non-executable constructs by executable ones:%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   113
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   114
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   115
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   116
\isadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   117
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   118
\endisadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   119
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   120
\isatagquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   121
\isacommand{lemma}\isamarkupfalse%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   122
\ {\isaliteral{5B}{\isacharbrackleft}}code{\isaliteral{5F}{\isacharunderscore}}unfold{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{3A}{\isacharcolon}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   123
\ \ {\isaliteral{22}{\isachardoublequoteopen}}x\ {\isaliteral{5C3C696E3E}{\isasymin}}\ set\ xs\ {\isaliteral{5C3C6C6F6E676C65667472696768746172726F773E}{\isasymlongleftrightarrow}}\ List{\isaliteral{2E}{\isachardot}}member\ xs\ x{\isaliteral{22}{\isachardoublequoteclose}}\ \isacommand{by}\isamarkupfalse%
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   124
\ {\isaliteral{28}{\isacharparenleft}}fact\ in{\isaliteral{5F}{\isacharunderscore}}set{\isaliteral{5F}{\isacharunderscore}}member{\isaliteral{29}{\isacharparenright}}%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   125
\endisatagquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   126
{\isafoldquote}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   127
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   128
\isadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   129
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   130
\endisadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   131
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   132
\begin{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   133
\item replacing executable but inconvenient constructs:%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   134
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   135
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   136
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   137
\isadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   138
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   139
\endisadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   140
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   141
\isatagquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   142
\isacommand{lemma}\isamarkupfalse%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   143
\ {\isaliteral{5B}{\isacharbrackleft}}code{\isaliteral{5F}{\isacharunderscore}}unfold{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{3A}{\isacharcolon}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   144
\ \ {\isaliteral{22}{\isachardoublequoteopen}}xs\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{5C3C6C6F6E676C65667472696768746172726F773E}{\isasymlongleftrightarrow}}\ List{\isaliteral{2E}{\isachardot}}null\ xs{\isaliteral{22}{\isachardoublequoteclose}}\ \isacommand{by}\isamarkupfalse%
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   145
\ {\isaliteral{28}{\isacharparenleft}}fact\ eq{\isaliteral{5F}{\isacharunderscore}}Nil{\isaliteral{5F}{\isacharunderscore}}null{\isaliteral{29}{\isacharparenright}}%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   146
\endisatagquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   147
{\isafoldquote}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   148
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   149
\isadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   150
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   151
\endisadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   152
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   153
\begin{isamarkuptext}%
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   154
\item eliminating disturbing expressions:%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   155
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   156
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   157
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   158
\isadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   159
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   160
\endisadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   161
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   162
\isatagquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   163
\isacommand{lemma}\isamarkupfalse%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   164
\ {\isaliteral{5B}{\isacharbrackleft}}code{\isaliteral{5F}{\isacharunderscore}}unfold{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{3A}{\isacharcolon}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   165
\ \ {\isaliteral{22}{\isachardoublequoteopen}}{\isadigit{1}}\ {\isaliteral{3D}{\isacharequal}}\ Suc\ {\isadigit{0}}{\isaliteral{22}{\isachardoublequoteclose}}\ \isacommand{by}\isamarkupfalse%
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   166
\ {\isaliteral{28}{\isacharparenleft}}fact\ One{\isaliteral{5F}{\isacharunderscore}}nat{\isaliteral{5F}{\isacharunderscore}}def{\isaliteral{29}{\isacharparenright}}%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   167
\endisatagquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   168
{\isafoldquote}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   169
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   170
\isadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   171
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   172
\endisadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   173
%
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   174
\end{itemize}
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   175
%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   176
\begin{isamarkuptext}%
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   177
\noindent \emph{Function transformers} provide a very general
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   178
  interface, transforming a list of function theorems to another list
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   179
  of function theorems, provided that neither the heading constant nor
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   180
  its type change.  The \isa{{\isadigit{0}}} / \isa{Suc} pattern
46523
7ca897381b26 update of generated documents
haftmann
parents: 45211
diff changeset
   181
  elimination implemented in theory \isa{Efficient{\isaliteral{5F}{\isacharunderscore}}Nat} (see
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   182
  \secref{eff_nat}) uses this interface.
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   183
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   184
  \noindent The current setup of the preprocessor may be inspected
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   185
  using the \indexdef{}{command}{print\_codeproc}\hypertarget{command.print-codeproc}{\hyperlink{command.print-codeproc}{\mbox{\isa{\isacommand{print{\isaliteral{5F}{\isacharunderscore}}codeproc}}}}} command.  \indexdef{}{command}{code\_thms}\hypertarget{command.code-thms}{\hyperlink{command.code-thms}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}thms}}}}} (see \secref{sec:equations}) provides a convenient
38505
2f8699695cf6 use command_def vs. command more consciously
haftmann
parents: 38440
diff changeset
   186
  mechanism to inspect the impact of a preprocessor setup on code
45211
3dd426ae6bea removed some remaining artefacts of ancient SML code generator
haftmann
parents: 43561
diff changeset
   187
  equations.%
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   188
\end{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   189
\isamarkuptrue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   190
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   191
\isamarkupsubsection{Understanding code equations \label{sec:equations}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   192
}
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   193
\isamarkuptrue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   194
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   195
\begin{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   196
As told in \secref{sec:principle}, the notion of code equations is
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   197
  vital to code generation.  Indeed most problems which occur in
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   198
  practice can be resolved by an inspection of the underlying code
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   199
  equations.
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   200
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   201
  It is possible to exchange the default code equations for constants
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   202
  by explicitly proving alternative ones:%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   203
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   204
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   205
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   206
\isadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   207
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   208
\endisadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   209
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   210
\isatagquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   211
\isacommand{lemma}\isamarkupfalse%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   212
\ {\isaliteral{5B}{\isacharbrackleft}}code{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{3A}{\isacharcolon}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   213
\ \ {\isaliteral{22}{\isachardoublequoteopen}}dequeue\ {\isaliteral{28}{\isacharparenleft}}AQueue\ xs\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   214
\ \ \ \ \ {\isaliteral{28}{\isacharparenleft}}if\ xs\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}\ then\ {\isaliteral{28}{\isacharparenleft}}None{\isaliteral{2C}{\isacharcomma}}\ AQueue\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{29}{\isacharparenright}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   215
\ \ \ \ \ \ \ else\ dequeue\ {\isaliteral{28}{\isacharparenleft}}AQueue\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{28}{\isacharparenleft}}rev\ xs{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   216
\ \ {\isaliteral{22}{\isachardoublequoteopen}}dequeue\ {\isaliteral{28}{\isacharparenleft}}AQueue\ xs\ {\isaliteral{28}{\isacharparenleft}}y\ {\isaliteral{23}{\isacharhash}}\ ys{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   217
\ \ \ \ \ {\isaliteral{28}{\isacharparenleft}}Some\ y{\isaliteral{2C}{\isacharcomma}}\ AQueue\ xs\ ys{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}\isanewline
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   218
\ \ \isacommand{by}\isamarkupfalse%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   219
\ {\isaliteral{28}{\isacharparenleft}}cases\ xs{\isaliteral{2C}{\isacharcomma}}\ simp{\isaliteral{5F}{\isacharunderscore}}all{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{28}{\isacharparenleft}}cases\ {\isaliteral{22}{\isachardoublequoteopen}}rev\ xs{\isaliteral{22}{\isachardoublequoteclose}}{\isaliteral{2C}{\isacharcomma}}\ simp{\isaliteral{5F}{\isacharunderscore}}all{\isaliteral{29}{\isacharparenright}}%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   220
\endisatagquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   221
{\isafoldquote}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   222
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   223
\isadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   224
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   225
\endisadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   226
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   227
\begin{isamarkuptext}%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   228
\noindent The annotation \isa{{\isaliteral{5B}{\isacharbrackleft}}code{\isaliteral{5D}{\isacharbrackright}}} is an \isa{attribute}
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   229
  which states that the given theorems should be considered as code
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   230
  equations for a \isa{fun} statement -- the corresponding constant
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   231
  is determined syntactically.  The resulting code:%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   232
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   233
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   234
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   235
\isadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   236
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   237
\endisadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   238
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   239
\isatagquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   240
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   241
\begin{isamarkuptext}%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   242
dequeue\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ forall\ a{\isaliteral{2E}{\isachardot}}\ Queue\ a\ {\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ {\isaliteral{28}{\isacharparenleft}}Maybe\ a{\isaliteral{2C}{\isacharcomma}}\ Queue\ a{\isaliteral{29}{\isacharparenright}}{\isaliteral{3B}{\isacharsemicolon}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   243
dequeue\ {\isaliteral{28}{\isacharparenleft}}AQueue\ xs\ {\isaliteral{28}{\isacharparenleft}}y\ {\isaliteral{3A}{\isacharcolon}}\ ys{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{28}{\isacharparenleft}}Just\ y{\isaliteral{2C}{\isacharcomma}}\ AQueue\ xs\ ys{\isaliteral{29}{\isacharparenright}}{\isaliteral{3B}{\isacharsemicolon}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   244
dequeue\ {\isaliteral{28}{\isacharparenleft}}AQueue\ xs\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   245
\ \ {\isaliteral{28}{\isacharparenleft}}if\ null\ xs\ then\ {\isaliteral{28}{\isacharparenleft}}Nothing{\isaliteral{2C}{\isacharcomma}}\ AQueue\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{29}{\isacharparenright}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   246
\ \ \ \ else\ dequeue\ {\isaliteral{28}{\isacharparenleft}}AQueue\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{28}{\isacharparenleft}}reverse\ xs{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{3B}{\isacharsemicolon}}\isanewline%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   247
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   248
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   249
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   250
\endisatagquotetypewriter
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   251
{\isafoldquotetypewriter}%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   252
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   253
\isadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   254
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   255
\endisadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   256
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   257
\begin{isamarkuptext}%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   258
\noindent You may note that the equality test \isa{xs\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}} has
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   259
  been replaced by the predicate \isa{List{\isaliteral{2E}{\isachardot}}null\ xs}.  This is due
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   260
  to the default setup of the \qn{preprocessor}.
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   261
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   262
  This possibility to select arbitrary code equations is the key
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   263
  technique for program and datatype refinement (see
39683
f75a01ee6c41 prefer typewrite tag over raw latex environment
haftmann
parents: 39664
diff changeset
   264
  \secref{sec:refinement}).
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   265
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   266
  Due to the preprocessor, there is the distinction of raw code
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   267
  equations (before preprocessing) and code equations (after
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   268
  preprocessing).
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   269
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   270
  The first can be listed (among other data) using the \indexdef{}{command}{print\_codesetup}\hypertarget{command.print-codesetup}{\hyperlink{command.print-codesetup}{\mbox{\isa{\isacommand{print{\isaliteral{5F}{\isacharunderscore}}codesetup}}}}} command.
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   271
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   272
  The code equations after preprocessing are already are blueprint of
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   273
  the generated program and can be inspected using the \hyperlink{command.code-thms}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}thms}}}} command:%
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   274
\end{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   275
\isamarkuptrue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   276
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   277
\isadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   278
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   279
\endisadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   280
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   281
\isatagquote
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   282
\isacommand{code{\isaliteral{5F}{\isacharunderscore}}thms}\isamarkupfalse%
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   283
\ dequeue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   284
\endisatagquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   285
{\isafoldquote}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   286
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   287
\isadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   288
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   289
\endisadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   290
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   291
\begin{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   292
\noindent This prints a table with the code equations for \isa{dequeue}, including \emph{all} code equations those equations depend
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   293
  on recursively.  These dependencies themselves can be visualized using
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   294
  the \indexdef{}{command}{code\_deps}\hypertarget{command.code-deps}{\hyperlink{command.code-deps}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}deps}}}}} command.%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   295
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   296
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   297
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   298
\isamarkupsubsection{Equality%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   299
}
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   300
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   301
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   302
\begin{isamarkuptext}%
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   303
Implementation of equality deserves some attention.  Here an example
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   304
  function involving polymorphic equality:%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   305
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   306
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   307
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   308
\isadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   309
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   310
\endisadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   311
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   312
\isatagquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   313
\isacommand{primrec}\isamarkupfalse%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   314
\ collect{\isaliteral{5F}{\isacharunderscore}}duplicates\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{27}{\isacharprime}}a\ list\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{27}{\isacharprime}}a\ list\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{27}{\isacharprime}}a\ list\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{27}{\isacharprime}}a\ list{\isaliteral{22}{\isachardoublequoteclose}}\ \isakeyword{where}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   315
\ \ {\isaliteral{22}{\isachardoublequoteopen}}collect{\isaliteral{5F}{\isacharunderscore}}duplicates\ xs\ ys\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{3D}{\isacharequal}}\ xs{\isaliteral{22}{\isachardoublequoteclose}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   316
{\isaliteral{7C}{\isacharbar}}\ {\isaliteral{22}{\isachardoublequoteopen}}collect{\isaliteral{5F}{\isacharunderscore}}duplicates\ xs\ ys\ {\isaliteral{28}{\isacharparenleft}}z{\isaliteral{23}{\isacharhash}}zs{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{28}{\isacharparenleft}}if\ z\ {\isaliteral{5C3C696E3E}{\isasymin}}\ set\ xs\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   317
\ \ \ \ then\ if\ z\ {\isaliteral{5C3C696E3E}{\isasymin}}\ set\ ys\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   318
\ \ \ \ \ \ then\ collect{\isaliteral{5F}{\isacharunderscore}}duplicates\ xs\ ys\ zs\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   319
\ \ \ \ \ \ else\ collect{\isaliteral{5F}{\isacharunderscore}}duplicates\ xs\ {\isaliteral{28}{\isacharparenleft}}z{\isaliteral{23}{\isacharhash}}ys{\isaliteral{29}{\isacharparenright}}\ zs\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   320
\ \ \ \ else\ collect{\isaliteral{5F}{\isacharunderscore}}duplicates\ {\isaliteral{28}{\isacharparenleft}}z{\isaliteral{23}{\isacharhash}}xs{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{28}{\isacharparenleft}}z{\isaliteral{23}{\isacharhash}}ys{\isaliteral{29}{\isacharparenright}}\ zs{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   321
\endisatagquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   322
{\isafoldquote}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   323
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   324
\isadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   325
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   326
\endisadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   327
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   328
\begin{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   329
\noindent During preprocessing, the membership test is rewritten,
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   330
  resulting in \isa{List{\isaliteral{2E}{\isachardot}}member}, which itself performs an explicit
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   331
  equality check, as can be seen in the corresponding \isa{SML} code:%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   332
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   333
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   334
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   335
\isadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   336
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   337
\endisadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   338
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   339
\isatagquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   340
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   341
\begin{isamarkuptext}%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   342
structure\ Example\ {\isaliteral{3A}{\isacharcolon}}\ sig\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   343
\ \ type\ {\isaliteral{27}{\isacharprime}}a\ equal\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   344
\ \ val\ equal\ {\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{27}{\isacharprime}}a\ equal\ {\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ {\isaliteral{27}{\isacharprime}}a\ {\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ {\isaliteral{27}{\isacharprime}}a\ {\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ bool\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   345
\ \ val\ eq\ {\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{27}{\isacharprime}}a\ equal\ {\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ {\isaliteral{27}{\isacharprime}}a\ {\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ {\isaliteral{27}{\isacharprime}}a\ {\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ bool\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   346
\ \ val\ member\ {\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{27}{\isacharprime}}a\ equal\ {\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ {\isaliteral{27}{\isacharprime}}a\ list\ {\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ {\isaliteral{27}{\isacharprime}}a\ {\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ bool\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   347
\ \ val\ collect{\isaliteral{5F}{\isacharunderscore}}duplicates\ {\isaliteral{3A}{\isacharcolon}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   348
\ \ \ \ {\isaliteral{27}{\isacharprime}}a\ equal\ {\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ {\isaliteral{27}{\isacharprime}}a\ list\ {\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ {\isaliteral{27}{\isacharprime}}a\ list\ {\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ {\isaliteral{27}{\isacharprime}}a\ list\ {\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ {\isaliteral{27}{\isacharprime}}a\ list\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   349
end\ {\isaliteral{3D}{\isacharequal}}\ struct\isanewline
39664
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   350
\isanewline
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   351
type\ {\isaliteral{27}{\isacharprime}}a\ equal\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{7B}{\isacharbraceleft}}equal\ {\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{27}{\isacharprime}}a\ {\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ {\isaliteral{27}{\isacharprime}}a\ {\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ bool{\isaliteral{7D}{\isacharbraceright}}{\isaliteral{3B}{\isacharsemicolon}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   352
val\ equal\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{23}{\isacharhash}}equal\ {\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{27}{\isacharprime}}a\ equal\ {\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ {\isaliteral{27}{\isacharprime}}a\ {\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ {\isaliteral{27}{\isacharprime}}a\ {\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ bool{\isaliteral{3B}{\isacharsemicolon}}\isanewline
39664
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   353
\isanewline
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   354
fun\ eq\ A{\isaliteral{5F}{\isacharunderscore}}\ a\ b\ {\isaliteral{3D}{\isacharequal}}\ equal\ A{\isaliteral{5F}{\isacharunderscore}}\ a\ b{\isaliteral{3B}{\isacharsemicolon}}\isanewline
39664
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   355
\isanewline
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   356
fun\ member\ A{\isaliteral{5F}{\isacharunderscore}}\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}\ y\ {\isaliteral{3D}{\isacharequal}}\ false\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   357
\ \ {\isaliteral{7C}{\isacharbar}}\ member\ A{\isaliteral{5F}{\isacharunderscore}}\ {\isaliteral{28}{\isacharparenleft}}x\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ xs{\isaliteral{29}{\isacharparenright}}\ y\ {\isaliteral{3D}{\isacharequal}}\ eq\ A{\isaliteral{5F}{\isacharunderscore}}\ x\ y\ orelse\ member\ A{\isaliteral{5F}{\isacharunderscore}}\ xs\ y{\isaliteral{3B}{\isacharsemicolon}}\isanewline
39664
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   358
\isanewline
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   359
fun\ collect{\isaliteral{5F}{\isacharunderscore}}duplicates\ A{\isaliteral{5F}{\isacharunderscore}}\ xs\ ys\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{3D}{\isacharequal}}\ xs\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   360
\ \ {\isaliteral{7C}{\isacharbar}}\ collect{\isaliteral{5F}{\isacharunderscore}}duplicates\ A{\isaliteral{5F}{\isacharunderscore}}\ xs\ ys\ {\isaliteral{28}{\isacharparenleft}}z\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ zs{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   361
\ \ \ \ {\isaliteral{28}{\isacharparenleft}}if\ member\ A{\isaliteral{5F}{\isacharunderscore}}\ xs\ z\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   362
\ \ \ \ \ \ then\ {\isaliteral{28}{\isacharparenleft}}if\ member\ A{\isaliteral{5F}{\isacharunderscore}}\ ys\ z\ then\ collect{\isaliteral{5F}{\isacharunderscore}}duplicates\ A{\isaliteral{5F}{\isacharunderscore}}\ xs\ ys\ zs\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   363
\ \ \ \ \ \ \ \ \ \ \ \ \ else\ collect{\isaliteral{5F}{\isacharunderscore}}duplicates\ A{\isaliteral{5F}{\isacharunderscore}}\ xs\ {\isaliteral{28}{\isacharparenleft}}z\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ ys{\isaliteral{29}{\isacharparenright}}\ zs{\isaliteral{29}{\isacharparenright}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   364
\ \ \ \ \ \ else\ collect{\isaliteral{5F}{\isacharunderscore}}duplicates\ A{\isaliteral{5F}{\isacharunderscore}}\ {\isaliteral{28}{\isacharparenleft}}z\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ xs{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{28}{\isacharparenleft}}z\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ ys{\isaliteral{29}{\isacharparenright}}\ zs{\isaliteral{29}{\isacharparenright}}{\isaliteral{3B}{\isacharsemicolon}}\isanewline
39664
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   365
\isanewline
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   366
end{\isaliteral{3B}{\isacharsemicolon}}\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{2A}{\isacharasterisk}}struct\ Example{\isaliteral{2A}{\isacharasterisk}}{\isaliteral{29}{\isacharparenright}}\isanewline%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   367
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   368
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   369
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   370
\endisatagquotetypewriter
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   371
{\isafoldquotetypewriter}%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   372
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   373
\isadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   374
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   375
\endisadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   376
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   377
\begin{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   378
\noindent Obviously, polymorphic equality is implemented the Haskell
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   379
  way using a type class.  How is this achieved?  HOL introduces an
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   380
  explicit class \isa{equal} with a corresponding operation \isa{equal{\isaliteral{5F}{\isacharunderscore}}class{\isaliteral{2E}{\isachardot}}equal} such that \isa{equal{\isaliteral{5F}{\isacharunderscore}}class{\isaliteral{2E}{\isachardot}}equal\ {\isaliteral{3D}{\isacharequal}}\ op\ {\isaliteral{3D}{\isacharequal}}}.  The preprocessing
39070
352bcd845998 updated
haftmann
parents: 38505
diff changeset
   381
  framework does the rest by propagating the \isa{equal} constraints
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   382
  through all dependent code equations.  For datatypes, instances of
39070
352bcd845998 updated
haftmann
parents: 38505
diff changeset
   383
  \isa{equal} are implicitly derived when possible.  For other types,
352bcd845998 updated
haftmann
parents: 38505
diff changeset
   384
  you may instantiate \isa{equal} manually like any other type class.%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   385
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   386
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   387
%
38440
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   388
\isamarkupsubsection{Explicit partiality \label{sec:partiality}%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   389
}
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   390
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   391
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   392
\begin{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   393
Partiality usually enters the game by partial patterns, as
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   394
  in the following example, again for amortised queues:%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   395
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   396
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   397
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   398
\isadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   399
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   400
\endisadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   401
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   402
\isatagquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   403
\isacommand{definition}\isamarkupfalse%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   404
\ strict{\isaliteral{5F}{\isacharunderscore}}dequeue\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{27}{\isacharprime}}a\ queue\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{27}{\isacharprime}}a\ {\isaliteral{5C3C74696D65733E}{\isasymtimes}}\ {\isaliteral{27}{\isacharprime}}a\ queue{\isaliteral{22}{\isachardoublequoteclose}}\ \isakeyword{where}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   405
\ \ {\isaliteral{22}{\isachardoublequoteopen}}strict{\isaliteral{5F}{\isacharunderscore}}dequeue\ q\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{28}{\isacharparenleft}}case\ dequeue\ q\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   406
\ \ \ \ of\ {\isaliteral{28}{\isacharparenleft}}Some\ x{\isaliteral{2C}{\isacharcomma}}\ q{\isaliteral{27}{\isacharprime}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{28}{\isacharparenleft}}x{\isaliteral{2C}{\isacharcomma}}\ q{\isaliteral{27}{\isacharprime}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}\isanewline
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   407
\isanewline
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   408
\isacommand{lemma}\isamarkupfalse%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   409
\ strict{\isaliteral{5F}{\isacharunderscore}}dequeue{\isaliteral{5F}{\isacharunderscore}}AQueue\ {\isaliteral{5B}{\isacharbrackleft}}code{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{3A}{\isacharcolon}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   410
\ \ {\isaliteral{22}{\isachardoublequoteopen}}strict{\isaliteral{5F}{\isacharunderscore}}dequeue\ {\isaliteral{28}{\isacharparenleft}}AQueue\ xs\ {\isaliteral{28}{\isacharparenleft}}y\ {\isaliteral{23}{\isacharhash}}\ ys{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{28}{\isacharparenleft}}y{\isaliteral{2C}{\isacharcomma}}\ AQueue\ xs\ ys{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   411
\ \ {\isaliteral{22}{\isachardoublequoteopen}}strict{\isaliteral{5F}{\isacharunderscore}}dequeue\ {\isaliteral{28}{\isacharparenleft}}AQueue\ xs\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   412
\ \ \ \ {\isaliteral{28}{\isacharparenleft}}case\ rev\ xs\ of\ y\ {\isaliteral{23}{\isacharhash}}\ ys\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{28}{\isacharparenleft}}y{\isaliteral{2C}{\isacharcomma}}\ AQueue\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}\ ys{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}\isanewline
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   413
\ \ \isacommand{by}\isamarkupfalse%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   414
\ {\isaliteral{28}{\isacharparenleft}}simp{\isaliteral{5F}{\isacharunderscore}}all\ add{\isaliteral{3A}{\isacharcolon}}\ strict{\isaliteral{5F}{\isacharunderscore}}dequeue{\isaliteral{5F}{\isacharunderscore}}def{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{28}{\isacharparenleft}}cases\ xs{\isaliteral{2C}{\isacharcomma}}\ simp{\isaliteral{5F}{\isacharunderscore}}all\ split{\isaliteral{3A}{\isacharcolon}}\ list{\isaliteral{2E}{\isachardot}}split{\isaliteral{29}{\isacharparenright}}%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   415
\endisatagquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   416
{\isafoldquote}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   417
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   418
\isadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   419
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   420
\endisadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   421
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   422
\begin{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   423
\noindent In the corresponding code, there is no equation
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   424
  for the pattern \isa{AQueue\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}}:%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   425
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   426
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   427
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   428
\isadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   429
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   430
\endisadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   431
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   432
\isatagquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   433
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   434
\begin{isamarkuptext}%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   435
strict{\isaliteral{5F}{\isacharunderscore}}dequeue\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ forall\ a{\isaliteral{2E}{\isachardot}}\ Queue\ a\ {\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ {\isaliteral{28}{\isacharparenleft}}a{\isaliteral{2C}{\isacharcomma}}\ Queue\ a{\isaliteral{29}{\isacharparenright}}{\isaliteral{3B}{\isacharsemicolon}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   436
strict{\isaliteral{5F}{\isacharunderscore}}dequeue\ {\isaliteral{28}{\isacharparenleft}}AQueue\ xs\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   437
\ \ let\ {\isaliteral{7B}{\isacharbraceleft}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   438
\ \ \ \ {\isaliteral{28}{\isacharparenleft}}y\ {\isaliteral{3A}{\isacharcolon}}\ ys{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ reverse\ xs{\isaliteral{3B}{\isacharsemicolon}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   439
\ \ {\isaliteral{7D}{\isacharbraceright}}\ in\ {\isaliteral{28}{\isacharparenleft}}y{\isaliteral{2C}{\isacharcomma}}\ AQueue\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}\ ys{\isaliteral{29}{\isacharparenright}}{\isaliteral{3B}{\isacharsemicolon}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   440
strict{\isaliteral{5F}{\isacharunderscore}}dequeue\ {\isaliteral{28}{\isacharparenleft}}AQueue\ xs\ {\isaliteral{28}{\isacharparenleft}}y\ {\isaliteral{3A}{\isacharcolon}}\ ys{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{28}{\isacharparenleft}}y{\isaliteral{2C}{\isacharcomma}}\ AQueue\ xs\ ys{\isaliteral{29}{\isacharparenright}}{\isaliteral{3B}{\isacharsemicolon}}\isanewline%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   441
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   442
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   443
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   444
\endisatagquotetypewriter
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   445
{\isafoldquotetypewriter}%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   446
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   447
\isadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   448
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   449
\endisadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   450
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   451
\begin{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   452
\noindent In some cases it is desirable to have this
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   453
  pseudo-\qt{partiality} more explicitly, e.g.~as follows:%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   454
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   455
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   456
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   457
\isadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   458
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   459
\endisadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   460
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   461
\isatagquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   462
\isacommand{axiomatization}\isamarkupfalse%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   463
\ empty{\isaliteral{5F}{\isacharunderscore}}queue\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{27}{\isacharprime}}a\isanewline
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   464
\isanewline
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   465
\isacommand{definition}\isamarkupfalse%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   466
\ strict{\isaliteral{5F}{\isacharunderscore}}dequeue{\isaliteral{27}{\isacharprime}}\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{27}{\isacharprime}}a\ queue\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{27}{\isacharprime}}a\ {\isaliteral{5C3C74696D65733E}{\isasymtimes}}\ {\isaliteral{27}{\isacharprime}}a\ queue{\isaliteral{22}{\isachardoublequoteclose}}\ \isakeyword{where}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   467
\ \ {\isaliteral{22}{\isachardoublequoteopen}}strict{\isaliteral{5F}{\isacharunderscore}}dequeue{\isaliteral{27}{\isacharprime}}\ q\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{28}{\isacharparenleft}}case\ dequeue\ q\ of\ {\isaliteral{28}{\isacharparenleft}}Some\ x{\isaliteral{2C}{\isacharcomma}}\ q{\isaliteral{27}{\isacharprime}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{28}{\isacharparenleft}}x{\isaliteral{2C}{\isacharcomma}}\ q{\isaliteral{27}{\isacharprime}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{7C}{\isacharbar}}\ {\isaliteral{5F}{\isacharunderscore}}\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ empty{\isaliteral{5F}{\isacharunderscore}}queue{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}\isanewline
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   468
\isanewline
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   469
\isacommand{lemma}\isamarkupfalse%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   470
\ strict{\isaliteral{5F}{\isacharunderscore}}dequeue{\isaliteral{27}{\isacharprime}}{\isaliteral{5F}{\isacharunderscore}}AQueue\ {\isaliteral{5B}{\isacharbrackleft}}code{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{3A}{\isacharcolon}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   471
\ \ {\isaliteral{22}{\isachardoublequoteopen}}strict{\isaliteral{5F}{\isacharunderscore}}dequeue{\isaliteral{27}{\isacharprime}}\ {\isaliteral{28}{\isacharparenleft}}AQueue\ xs\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{28}{\isacharparenleft}}if\ xs\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}\ then\ empty{\isaliteral{5F}{\isacharunderscore}}queue\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   472
\ \ \ \ \ else\ strict{\isaliteral{5F}{\isacharunderscore}}dequeue{\isaliteral{27}{\isacharprime}}\ {\isaliteral{28}{\isacharparenleft}}AQueue\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{28}{\isacharparenleft}}rev\ xs{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   473
\ \ {\isaliteral{22}{\isachardoublequoteopen}}strict{\isaliteral{5F}{\isacharunderscore}}dequeue{\isaliteral{27}{\isacharprime}}\ {\isaliteral{28}{\isacharparenleft}}AQueue\ xs\ {\isaliteral{28}{\isacharparenleft}}y\ {\isaliteral{23}{\isacharhash}}\ ys{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   474
\ \ \ \ \ {\isaliteral{28}{\isacharparenleft}}y{\isaliteral{2C}{\isacharcomma}}\ AQueue\ xs\ ys{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}\isanewline
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   475
\ \ \isacommand{by}\isamarkupfalse%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   476
\ {\isaliteral{28}{\isacharparenleft}}simp{\isaliteral{5F}{\isacharunderscore}}all\ add{\isaliteral{3A}{\isacharcolon}}\ strict{\isaliteral{5F}{\isacharunderscore}}dequeue{\isaliteral{27}{\isacharprime}}{\isaliteral{5F}{\isacharunderscore}}def\ split{\isaliteral{3A}{\isacharcolon}}\ list{\isaliteral{2E}{\isachardot}}splits{\isaliteral{29}{\isacharparenright}}%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   477
\endisatagquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   478
{\isafoldquote}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   479
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   480
\isadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   481
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   482
\endisadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   483
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   484
\begin{isamarkuptext}%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   485
Observe that on the right hand side of the definition of \isa{strict{\isaliteral{5F}{\isacharunderscore}}dequeue{\isaliteral{27}{\isacharprime}}}, the unspecified constant \isa{empty{\isaliteral{5F}{\isacharunderscore}}queue} occurs.
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   486
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   487
  Normally, if constants without any code equations occur in a
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   488
  program, the code generator complains (since in most cases this is
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   489
  indeed an error).  But such constants can also be thought
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   490
  of as function definitions which always fail,
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   491
  since there is never a successful pattern match on the left hand
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   492
  side.  In order to categorise a constant into that category
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   493
  explicitly, use \indexdef{}{command}{code\_abort}\hypertarget{command.code-abort}{\hyperlink{command.code-abort}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}abort}}}}}:%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   494
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   495
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   496
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   497
\isadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   498
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   499
\endisadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   500
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   501
\isatagquote
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   502
\isacommand{code{\isaliteral{5F}{\isacharunderscore}}abort}\isamarkupfalse%
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   503
\ empty{\isaliteral{5F}{\isacharunderscore}}queue%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   504
\endisatagquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   505
{\isafoldquote}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   506
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   507
\isadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   508
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   509
\endisadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   510
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   511
\begin{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   512
\noindent Then the code generator will just insert an error or
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   513
  exception at the appropriate position:%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   514
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   515
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   516
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   517
\isadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   518
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   519
\endisadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   520
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   521
\isatagquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   522
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   523
\begin{isamarkuptext}%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   524
empty{\isaliteral{5F}{\isacharunderscore}}queue\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ forall\ a{\isaliteral{2E}{\isachardot}}\ a{\isaliteral{3B}{\isacharsemicolon}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   525
empty{\isaliteral{5F}{\isacharunderscore}}queue\ {\isaliteral{3D}{\isacharequal}}\ error\ {\isaliteral{22}{\isachardoublequote}}empty{\isaliteral{5F}{\isacharunderscore}}queue{\isaliteral{22}{\isachardoublequote}}{\isaliteral{3B}{\isacharsemicolon}}\isanewline
39664
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   526
\isanewline
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   527
strict{\isaliteral{5F}{\isacharunderscore}}dequeue\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ forall\ a{\isaliteral{2E}{\isachardot}}\ Queue\ a\ {\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ {\isaliteral{28}{\isacharparenleft}}a{\isaliteral{2C}{\isacharcomma}}\ Queue\ a{\isaliteral{29}{\isacharparenright}}{\isaliteral{3B}{\isacharsemicolon}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   528
strict{\isaliteral{5F}{\isacharunderscore}}dequeue\ {\isaliteral{28}{\isacharparenleft}}AQueue\ xs\ {\isaliteral{28}{\isacharparenleft}}y\ {\isaliteral{3A}{\isacharcolon}}\ ys{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{28}{\isacharparenleft}}y{\isaliteral{2C}{\isacharcomma}}\ AQueue\ xs\ ys{\isaliteral{29}{\isacharparenright}}{\isaliteral{3B}{\isacharsemicolon}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   529
strict{\isaliteral{5F}{\isacharunderscore}}dequeue\ {\isaliteral{28}{\isacharparenleft}}AQueue\ xs\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   530
\ \ {\isaliteral{28}{\isacharparenleft}}if\ null\ xs\ then\ empty{\isaliteral{5F}{\isacharunderscore}}queue\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   531
\ \ \ \ else\ strict{\isaliteral{5F}{\isacharunderscore}}dequeue\ {\isaliteral{28}{\isacharparenleft}}AQueue\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{28}{\isacharparenleft}}reverse\ xs{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{3B}{\isacharsemicolon}}\isanewline%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   532
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   533
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   534
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   535
\endisatagquotetypewriter
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   536
{\isafoldquotetypewriter}%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   537
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   538
\isadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   539
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   540
\endisadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   541
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   542
\begin{isamarkuptext}%
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   543
\noindent This feature however is rarely needed in practice.  Note
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   544
  also that the HOL default setup already declares \isa{undefined}
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   545
  as \hyperlink{command.code-abort}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}abort}}}}, which is most likely to be used in such
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   546
  situations.%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   547
\end{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   548
\isamarkuptrue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   549
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   550
\isamarkupsubsection{If something goes utterly wrong \label{sec:utterly_wrong}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   551
}
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   552
\isamarkuptrue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   553
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   554
\begin{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   555
Under certain circumstances, the code generator fails to produce
38440
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   556
  code entirely.  To debug these, the following hints may prove
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   557
  helpful:
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   558
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   559
  \begin{description}
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   560
38440
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   561
    \ditem{\emph{Check with a different target language}.}  Sometimes
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   562
      the situation gets more clear if you switch to another target
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   563
      language; the code generated there might give some hints what
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   564
      prevents the code generator to produce code for the desired
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   565
      language.
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   566
38440
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   567
    \ditem{\emph{Inspect code equations}.}  Code equations are the central
43561
2bb6fd55e195 updated generated file;
wenzelm
parents: 43409
diff changeset
   568
      carrier of code generation.  Most problems occurring while generating
38440
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   569
      code can be traced to single equations which are printed as part of
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   570
      the error message.  A closer inspection of those may offer the key
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   571
      for solving issues (cf.~\secref{sec:equations}).
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   572
38440
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   573
    \ditem{\emph{Inspect preprocessor setup}.}  The preprocessor might
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   574
      transform code equations unexpectedly; to understand an
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   575
      inspection of its setup is necessary (cf.~\secref{sec:preproc}).
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   576
38440
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   577
    \ditem{\emph{Generate exceptions}.}  If the code generator
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   578
      complains about missing code equations, in can be helpful to
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   579
      implement the offending constants as exceptions
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   580
      (cf.~\secref{sec:partiality}); this allows at least for a formal
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   581
      generation of code, whose inspection may then give clues what is
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   582
      wrong.
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   583
38440
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   584
    \ditem{\emph{Remove offending code equations}.}  If code
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   585
      generation is prevented by just a single equation, this can be
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   586
      removed (cf.~\secref{sec:equations}) to allow formal code
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   587
      generation, whose result in turn can be used to trace the
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   588
      problem.  The most prominent case here are mismatches in type
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   589
      class signatures (\qt{wellsortedness error}).
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   590
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   591
  \end{description}%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   592
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   593
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   594
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   595
\isadelimtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   596
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   597
\endisadelimtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   598
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   599
\isatagtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   600
\isacommand{end}\isamarkupfalse%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   601
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   602
\endisatagtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   603
{\isafoldtheory}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   604
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   605
\isadelimtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   606
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   607
\endisadelimtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   608
\isanewline
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   609
\end{isabellebody}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   610
%%% Local Variables:
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   611
%%% mode: latex
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   612
%%% TeX-master: "root"
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   613
%%% End: