doc-src/Codegen/Thy/document/Foundations.tex
author wenzelm
Mon, 27 Jun 2011 17:06:06 +0200
changeset 43561 2bb6fd55e195
parent 43409 868a748b162a
child 45211 3dd426ae6bea
permissions -rw-r--r--
updated generated file;
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
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    34
  \hyperlink{theory.Pure}{\mbox{\isa{Pure}}}.  Practically, the object logic \hyperlink{theory.HOL}{\mbox{\isa{HOL}}}
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    35
  provides the necessary facilities to make use of the code generator,
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
    36
  mainly since it is an extension of \hyperlink{theory.Pure}{\mbox{\isa{Pure}}}.
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
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   181
  elimination implemented in theory \hyperlink{theory.Efficient-Nat}{\mbox{\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
2f8699695cf6 use command_def vs. command more consciously
haftmann
parents: 38440
diff changeset
   187
  equations.
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   188
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   189
  \begin{warn}
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   190
    Attribute \hyperlink{attribute.code-unfold}{\mbox{\isa{code{\isaliteral{5F}{\isacharunderscore}}unfold}}} also applies to the
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   191
    preprocessor of the ancient \isa{SML\ code\ generator}; in case
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   192
    this is not what you intend, use \hyperlink{attribute.code-inline}{\mbox{\isa{code{\isaliteral{5F}{\isacharunderscore}}inline}}} instead.
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   193
  \end{warn}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   194
\end{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   195
\isamarkuptrue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   196
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   197
\isamarkupsubsection{Understanding code equations \label{sec:equations}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   198
}
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   199
\isamarkuptrue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   200
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   201
\begin{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   202
As told in \secref{sec:principle}, the notion of code equations is
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   203
  vital to code generation.  Indeed most problems which occur in
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   204
  practice can be resolved by an inspection of the underlying code
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   205
  equations.
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   206
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   207
  It is possible to exchange the default code equations for constants
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   208
  by explicitly proving alternative ones:%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   209
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   210
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   211
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   212
\isadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   213
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   214
\endisadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   215
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   216
\isatagquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   217
\isacommand{lemma}\isamarkupfalse%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   218
\ {\isaliteral{5B}{\isacharbrackleft}}code{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{3A}{\isacharcolon}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   219
\ \ {\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
   220
\ \ \ \ \ {\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
   221
\ \ \ \ \ \ \ 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
   222
\ \ {\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
   223
\ \ \ \ \ {\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
   224
\ \ \isacommand{by}\isamarkupfalse%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   225
\ {\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
   226
\endisatagquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   227
{\isafoldquote}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   228
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   229
\isadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   230
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   231
\endisadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   232
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   233
\begin{isamarkuptext}%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   234
\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
   235
  which states that the given theorems should be considered as code
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   236
  equations for a \isa{fun} statement -- the corresponding constant
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   237
  is determined syntactically.  The resulting code:%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   238
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   239
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   240
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   241
\isadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   242
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   243
\endisadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   244
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   245
\isatagquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   246
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   247
\begin{isamarkuptext}%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   248
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
   249
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
   250
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
   251
\ \ {\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
   252
\ \ \ \ 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
   253
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   254
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   255
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   256
\endisatagquotetypewriter
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   257
{\isafoldquotetypewriter}%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   258
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   259
\isadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   260
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   261
\endisadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   262
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   263
\begin{isamarkuptext}%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   264
\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
   265
  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
   266
  to the default setup of the \qn{preprocessor}.
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   267
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   268
  This possibility to select arbitrary code equations is the key
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   269
  technique for program and datatype refinement (see
39683
f75a01ee6c41 prefer typewrite tag over raw latex environment
haftmann
parents: 39664
diff changeset
   270
  \secref{sec:refinement}).
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   271
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   272
  Due to the preprocessor, there is the distinction of raw code
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   273
  equations (before preprocessing) and code equations (after
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   274
  preprocessing).
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   275
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   276
  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
   277
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   278
  The code equations after preprocessing are already are blueprint of
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   279
  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
   280
\end{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   281
\isamarkuptrue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   282
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   283
\isadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   284
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   285
\endisadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   286
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   287
\isatagquote
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   288
\isacommand{code{\isaliteral{5F}{\isacharunderscore}}thms}\isamarkupfalse%
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   289
\ dequeue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   290
\endisatagquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   291
{\isafoldquote}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   292
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   293
\isadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   294
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   295
\endisadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   296
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   297
\begin{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   298
\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
   299
  on recursively.  These dependencies themselves can be visualized using
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   300
  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
   301
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   302
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   303
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   304
\isamarkupsubsection{Equality%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   305
}
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
\begin{isamarkuptext}%
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   309
Implementation of equality deserves some attention.  Here an example
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   310
  function involving polymorphic equality:%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   311
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   312
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   313
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   314
\isadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   315
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   316
\endisadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   317
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   318
\isatagquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   319
\isacommand{primrec}\isamarkupfalse%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   320
\ 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
   321
\ \ {\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
   322
{\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
   323
\ \ \ \ then\ if\ z\ {\isaliteral{5C3C696E3E}{\isasymin}}\ set\ ys\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   324
\ \ \ \ \ \ then\ collect{\isaliteral{5F}{\isacharunderscore}}duplicates\ xs\ ys\ zs\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   325
\ \ \ \ \ \ 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
   326
\ \ \ \ 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
   327
\endisatagquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   328
{\isafoldquote}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   329
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   330
\isadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   331
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   332
\endisadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   333
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   334
\begin{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   335
\noindent During preprocessing, the membership test is rewritten,
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   336
  resulting in \isa{List{\isaliteral{2E}{\isachardot}}member}, which itself performs an explicit
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   337
  equality check, as can be seen in the corresponding \isa{SML} code:%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   338
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   339
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   340
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   341
\isadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   342
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   343
\endisadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   344
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   345
\isatagquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   346
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   347
\begin{isamarkuptext}%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   348
structure\ Example\ {\isaliteral{3A}{\isacharcolon}}\ sig\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   349
\ \ type\ {\isaliteral{27}{\isacharprime}}a\ equal\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   350
\ \ 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
   351
\ \ 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
   352
\ \ 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
   353
\ \ val\ collect{\isaliteral{5F}{\isacharunderscore}}duplicates\ {\isaliteral{3A}{\isacharcolon}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   354
\ \ \ \ {\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
   355
end\ {\isaliteral{3D}{\isacharequal}}\ struct\isanewline
39664
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   356
\isanewline
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   357
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
   358
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
   359
\isanewline
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   360
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
   361
\isanewline
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   362
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
   363
\ \ {\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
   364
\isanewline
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   365
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
   366
\ \ {\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
   367
\ \ \ \ {\isaliteral{28}{\isacharparenleft}}if\ member\ A{\isaliteral{5F}{\isacharunderscore}}\ xs\ z\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   368
\ \ \ \ \ \ 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
   369
\ \ \ \ \ \ \ \ \ \ \ \ \ 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
   370
\ \ \ \ \ \ 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
   371
\isanewline
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   372
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
   373
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   374
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   375
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   376
\endisatagquotetypewriter
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   377
{\isafoldquotetypewriter}%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   378
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   379
\isadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   380
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   381
\endisadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   382
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   383
\begin{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   384
\noindent Obviously, polymorphic equality is implemented the Haskell
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   385
  way using a type class.  How is this achieved?  HOL introduces an
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   386
  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
   387
  framework does the rest by propagating the \isa{equal} constraints
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   388
  through all dependent code equations.  For datatypes, instances of
39070
352bcd845998 updated
haftmann
parents: 38505
diff changeset
   389
  \isa{equal} are implicitly derived when possible.  For other types,
352bcd845998 updated
haftmann
parents: 38505
diff changeset
   390
  you may instantiate \isa{equal} manually like any other type class.%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   391
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   392
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   393
%
38440
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   394
\isamarkupsubsection{Explicit partiality \label{sec:partiality}%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   395
}
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
\begin{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   399
Partiality usually enters the game by partial patterns, as
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   400
  in the following example, again for amortised queues:%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   401
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   402
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   403
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   404
\isadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   405
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   406
\endisadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   407
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   408
\isatagquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   409
\isacommand{definition}\isamarkupfalse%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   410
\ 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
   411
\ \ {\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
   412
\ \ \ \ 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
   413
\isanewline
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   414
\isacommand{lemma}\isamarkupfalse%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   415
\ 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
   416
\ \ {\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
   417
\ \ {\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
   418
\ \ \ \ {\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
   419
\ \ \isacommand{by}\isamarkupfalse%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   420
\ {\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
   421
\endisatagquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   422
{\isafoldquote}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   423
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   424
\isadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   425
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   426
\endisadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   427
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   428
\begin{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   429
\noindent In the corresponding code, there is no equation
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   430
  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
   431
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   432
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   433
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   434
\isadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   435
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   436
\endisadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   437
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   438
\isatagquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   439
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   440
\begin{isamarkuptext}%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   441
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
   442
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
   443
\ \ let\ {\isaliteral{7B}{\isacharbraceleft}}\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   444
\ \ \ \ {\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
   445
\ \ {\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
   446
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
   447
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   448
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   449
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   450
\endisatagquotetypewriter
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   451
{\isafoldquotetypewriter}%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   452
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   453
\isadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   454
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   455
\endisadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   456
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   457
\begin{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   458
\noindent In some cases it is desirable to have this
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   459
  pseudo-\qt{partiality} more explicitly, e.g.~as follows:%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   460
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   461
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   462
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   463
\isadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   464
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   465
\endisadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   466
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   467
\isatagquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   468
\isacommand{axiomatization}\isamarkupfalse%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   469
\ 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
   470
\isanewline
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   471
\isacommand{definition}\isamarkupfalse%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   472
\ 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
   473
\ \ {\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
   474
\isanewline
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   475
\isacommand{lemma}\isamarkupfalse%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   476
\ 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
   477
\ \ {\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
   478
\ \ \ \ \ 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
   479
\ \ {\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
   480
\ \ \ \ \ {\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
   481
\ \ \isacommand{by}\isamarkupfalse%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   482
\ {\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
   483
\endisatagquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   484
{\isafoldquote}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   485
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   486
\isadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   487
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   488
\endisadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   489
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   490
\begin{isamarkuptext}%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   491
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
   492
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   493
  Normally, if constants without any code equations occur in a
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   494
  program, the code generator complains (since in most cases this is
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   495
  indeed an error).  But such constants can also be thought
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   496
  of as function definitions which always fail,
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   497
  since there is never a successful pattern match on the left hand
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   498
  side.  In order to categorise a constant into that category
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   499
  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
   500
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   501
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   502
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   503
\isadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   504
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   505
\endisadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   506
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   507
\isatagquote
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   508
\isacommand{code{\isaliteral{5F}{\isacharunderscore}}abort}\isamarkupfalse%
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   509
\ empty{\isaliteral{5F}{\isacharunderscore}}queue%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   510
\endisatagquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   511
{\isafoldquote}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   512
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   513
\isadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   514
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   515
\endisadelimquote
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   516
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   517
\begin{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   518
\noindent Then the code generator will just insert an error or
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   519
  exception at the appropriate position:%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   520
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   521
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   522
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   523
\isadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   524
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   525
\endisadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   526
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   527
\isatagquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   528
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   529
\begin{isamarkuptext}%
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   530
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
   531
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
   532
\isanewline
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   533
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
   534
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
   535
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
   536
\ \ {\isaliteral{28}{\isacharparenleft}}if\ null\ xs\ then\ empty{\isaliteral{5F}{\isacharunderscore}}queue\isanewline
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   537
\ \ \ \ 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
   538
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   539
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   540
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   541
\endisatagquotetypewriter
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   542
{\isafoldquotetypewriter}%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   543
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   544
\isadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   545
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   546
\endisadelimquotetypewriter
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   547
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   548
\begin{isamarkuptext}%
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   549
\noindent This feature however is rarely needed in practice.  Note
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   550
  also that the HOL default setup already declares \isa{undefined}
40406
313a24b66a8d updated generated files;
wenzelm
parents: 39745
diff changeset
   551
  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
   552
  situations.%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   553
\end{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   554
\isamarkuptrue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   555
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   556
\isamarkupsubsection{If something goes utterly wrong \label{sec:utterly_wrong}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   557
}
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   558
\isamarkuptrue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   559
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   560
\begin{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   561
Under certain circumstances, the code generator fails to produce
38440
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   562
  code entirely.  To debug these, the following hints may prove
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   563
  helpful:
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   564
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   565
  \begin{description}
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{Check with a different target language}.}  Sometimes
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   568
      the situation gets more clear if you switch to another target
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   569
      language; the code generated there might give some hints what
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   570
      prevents the code generator to produce code for the desired
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   571
      language.
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 code equations}.}  Code equations are the central
43561
2bb6fd55e195 updated generated file;
wenzelm
parents: 43409
diff changeset
   574
      carrier of code generation.  Most problems occurring while generating
38440
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   575
      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
   576
      the error message.  A closer inspection of those may offer the key
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   577
      for solving issues (cf.~\secref{sec:equations}).
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   578
38440
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   579
    \ditem{\emph{Inspect preprocessor setup}.}  The preprocessor might
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   580
      transform code equations unexpectedly; to understand an
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   581
      inspection of its setup is necessary (cf.~\secref{sec:preproc}).
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   582
38440
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   583
    \ditem{\emph{Generate exceptions}.}  If the code generator
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   584
      complains about missing code equations, in can be helpful to
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   585
      implement the offending constants as exceptions
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   586
      (cf.~\secref{sec:partiality}); this allows at least for a formal
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   587
      generation of code, whose inspection may then give clues what is
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   588
      wrong.
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   589
38440
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   590
    \ditem{\emph{Remove offending code equations}.}  If code
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   591
      generation is prevented by just a single equation, this can be
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   592
      removed (cf.~\secref{sec:equations}) to allow formal code
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   593
      generation, whose result in turn can be used to trace the
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   594
      problem.  The most prominent case here are mismatches in type
6c0d02f416ba section "if something goes utterly wrong"
haftmann
parents: 38437
diff changeset
   595
      class signatures (\qt{wellsortedness error}).
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   596
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38406
diff changeset
   597
  \end{description}%
38406
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   598
\end{isamarkuptext}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   599
\isamarkuptrue%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   600
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   601
\isadelimtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   602
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   603
\endisadelimtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   604
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   605
\isatagtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   606
\isacommand{end}\isamarkupfalse%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   607
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   608
\endisatagtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   609
{\isafoldtheory}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   610
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   611
\isadelimtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   612
%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   613
\endisadelimtheory
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   614
\isanewline
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   615
\end{isabellebody}%
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   616
%%% Local Variables:
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   617
%%% mode: latex
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   618
%%% TeX-master: "root"
bbb02b67caac sketch of new outline
haftmann
parents:
diff changeset
   619
%%% End: