doc-src/Codegen/Thy/document/Adaptation.tex
author haftmann
Tue, 17 Aug 2010 14:19:12 +0200
changeset 38459 cfe74b0eecb1
parent 38450 ada5814c9d87
child 38505 2f8699695cf6
permissions -rw-r--r--
reworked section on simple datatype refinement
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
     1
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
     2
\begin{isabellebody}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
     3
\def\isabellecontext{Adaptation}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
     4
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
     5
\isadelimtheory
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
     6
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
     7
\endisadelimtheory
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
     8
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
     9
\isatagtheory
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    10
\isacommand{theory}\isamarkupfalse%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    11
\ Adaptation\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    12
\isakeyword{imports}\ Setup\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    13
\isakeyword{begin}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    14
\endisatagtheory
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    15
{\isafoldtheory}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    16
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    17
\isadelimtheory
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    18
\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    19
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    20
\endisadelimtheory
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    21
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    22
\isadeliminvisible
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    23
\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    24
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    25
\endisadeliminvisible
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    26
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    27
\isataginvisible
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    28
\isacommand{setup}\isamarkupfalse%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    29
\ {\isacharverbatimopen}\ Code{\isacharunderscore}Target{\isachardot}extend{\isacharunderscore}target\ {\isacharparenleft}{\isachardoublequote}{\isasymSML}{\isachardoublequote}{\isacharcomma}\ {\isacharparenleft}{\isachardoublequote}SML{\isachardoublequote}{\isacharcomma}\ K\ I{\isacharparenright}{\isacharparenright}\ {\isacharverbatimclose}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    30
\endisataginvisible
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    31
{\isafoldinvisible}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    32
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    33
\isadeliminvisible
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    34
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    35
\endisadeliminvisible
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    36
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    37
\isamarkupsection{Adaptation to target languages \label{sec:adaptation}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    38
}
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    39
\isamarkuptrue%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    40
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    41
\isamarkupsubsection{Adapting code generation%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    42
}
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    43
\isamarkuptrue%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    44
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    45
\begin{isamarkuptext}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    46
The aspects of code generation introduced so far have two aspects
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    47
  in common:
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    48
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    49
  \begin{itemize}
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
    50
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
    51
    \item They act uniformly, without reference to a specific target
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
    52
       language.
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
    53
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    54
    \item They are \emph{safe} in the sense that as long as you trust
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    55
       the code generator meta theory and implementation, you cannot
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
    56
       produce programs that yield results which are not derivable in
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
    57
       the logic.
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
    58
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    59
  \end{itemize}
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    60
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
    61
  \noindent In this section we will introduce means to \emph{adapt}
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
    62
  the serialiser to a specific target language, i.e.~to print program
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
    63
  fragments in a way which accommodates \qt{already existing}
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
    64
  ingredients of a target language environment, for three reasons:
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    65
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    66
  \begin{itemize}
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    67
    \item improving readability and aesthetics of generated code
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    68
    \item gaining efficiency
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    69
    \item interface with language parts which have no direct counterpart
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    70
      in \isa{HOL} (say, imperative data structures)
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    71
  \end{itemize}
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    72
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    73
  \noindent Generally, you should avoid using those features yourself
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    74
  \emph{at any cost}:
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    75
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    76
  \begin{itemize}
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
    77
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
    78
    \item The safe configuration methods act uniformly on every target
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
    79
      language, whereas for adaptation you have to treat each target
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
    80
      language separately.
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
    81
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
    82
    \item Application is extremely tedious since there is no
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
    83
      abstraction which would allow for a static check, making it easy
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
    84
      to produce garbage.
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
    85
34155
14aaccb399b3 Polishing up the English
paulson
parents: 33707
diff changeset
    86
    \item Subtle errors can be introduced unconsciously.
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
    87
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    88
  \end{itemize}
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    89
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
    90
  \noindent However, even if you ought refrain from setting up
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
    91
  adaptation yourself, already the \isa{HOL} comes with some
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
    92
  reasonable default adaptations (say, using target language list
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
    93
  syntax).  There also some common adaptation cases which you can
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
    94
  setup by importing particular library theories.  In order to
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
    95
  understand these, we provide some clues here; these however are not
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
    96
  supposed to replace a careful study of the sources.%
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    97
\end{isamarkuptext}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    98
\isamarkuptrue%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
    99
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   100
\isamarkupsubsection{The adaptation principle%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   101
}
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   102
\isamarkuptrue%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   103
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   104
\begin{isamarkuptext}%
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   105
Figure \ref{fig:adaptation} illustrates what \qt{adaptation} is
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   106
  conceptually supposed to be:
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   107
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   108
  \begin{figure}[here]
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   109
    \includegraphics{adaptation}
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   110
    \caption{The adaptation principle}
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   111
    \label{fig:adaptation}
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   112
  \end{figure}
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   113
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   114
  \noindent In the tame view, code generation acts as broker between
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   115
  \isa{logic}, \isa{intermediate\ language} and \isa{target\ language} by means of \isa{translation} and \isa{serialisation}; for the latter, the serialiser has to observe the
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   116
  structure of the \isa{language} itself plus some \isa{reserved}
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   117
  keywords which have to be avoided for generated code.  However, if
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   118
  you consider \isa{adaptation} mechanisms, the code generated by
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   119
  the serializer is just the tip of the iceberg:
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   120
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   121
  \begin{itemize}
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   122
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   123
    \item \isa{serialisation} can be \emph{parametrised} such that
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   124
      logical entities are mapped to target-specific ones
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   125
      (e.g. target-specific list syntax, see also
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   126
      \secref{sec:adaptation_mechanisms})
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   127
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   128
    \item Such parametrisations can involve references to a
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   129
      target-specific standard \isa{library} (e.g. using the \isa{Haskell} \verb|Maybe| type instead of the \isa{HOL}
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   130
      \isa{option} type); if such are used, the corresponding
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   131
      identifiers (in our example, \verb|Maybe|, \verb|Nothing| and \verb|Just|) also have to be considered \isa{reserved}.
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   132
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   133
    \item Even more, the user can enrich the library of the
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   134
      target-language by providing code snippets (\qt{\isa{includes}}) which are prepended to any generated code (see
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   135
      \secref{sec:include}); this typically also involves further
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   136
      \isa{reserved} identifiers.
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   137
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   138
  \end{itemize}
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   139
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   140
  \noindent As figure \ref{fig:adaptation} illustrates, all these
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   141
  adaptation mechanisms have to act consistently; it is at the
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   142
  discretion of the user to take care for this.%
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   143
\end{isamarkuptext}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   144
\isamarkuptrue%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   145
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   146
\isamarkupsubsection{Common adaptation patterns%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   147
}
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   148
\isamarkuptrue%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   149
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   150
\begin{isamarkuptext}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   151
The \hyperlink{theory.HOL}{\mbox{\isa{HOL}}} \hyperlink{theory.Main}{\mbox{\isa{Main}}} theory already provides a code
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   152
  generator setup which should be suitable for most applications.
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   153
  Common extensions and modifications are available by certain
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   154
  theories of the \isa{HOL} library; beside being useful in
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   155
  applications, they may serve as a tutorial for customising the code
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   156
  generator setup (see below \secref{sec:adaptation_mechanisms}).
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   157
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   158
  \begin{description}
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   159
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   160
    \item[\hyperlink{theory.Code-Integer}{\mbox{\isa{Code{\isacharunderscore}Integer}}}] represents \isa{HOL} integers by
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   161
       big integer literals in target languages.
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   162
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   163
    \item[\hyperlink{theory.Code-Char}{\mbox{\isa{Code{\isacharunderscore}Char}}}] represents \isa{HOL} characters by
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   164
       character literals in target languages.
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   165
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   166
    \item[\hyperlink{theory.Code-Char-chr}{\mbox{\isa{Code{\isacharunderscore}Char{\isacharunderscore}chr}}}] like \isa{Code{\isacharunderscore}Char}, but
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   167
       also offers treatment of character codes; includes \hyperlink{theory.Code-Char}{\mbox{\isa{Code{\isacharunderscore}Char}}}.
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   168
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   169
    \item[\hyperlink{theory.Efficient-Nat}{\mbox{\isa{Efficient{\isacharunderscore}Nat}}}] \label{eff_nat} implements
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   170
       natural numbers by integers, which in general will result in
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   171
       higher efficiency; pattern matching with \isa{{\isadigit{0}}} /
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   172
       \isa{Suc} is eliminated; includes \hyperlink{theory.Code-Integer}{\mbox{\isa{Code{\isacharunderscore}Integer}}}
31206
a9fa62683582 adjusted to changed theory name
haftmann
parents: 31150
diff changeset
   173
       and \hyperlink{theory.Code-Numeral}{\mbox{\isa{Code{\isacharunderscore}Numeral}}}.
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   174
31206
a9fa62683582 adjusted to changed theory name
haftmann
parents: 31150
diff changeset
   175
    \item[\hyperlink{theory.Code-Numeral}{\mbox{\isa{Code{\isacharunderscore}Numeral}}}] provides an additional datatype
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   176
       \isa{index} which is mapped to target-language built-in
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   177
       integers.  Useful for code setups which involve e.g.~indexing
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   178
       of target-language arrays.
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   179
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   180
    \item[\hyperlink{theory.String}{\mbox{\isa{String}}}] provides an additional datatype \isa{String{\isachardot}literal} which is isomorphic to strings; \isa{String{\isachardot}literal}s are mapped to target-language strings.  Useful
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   181
       for code setups which involve e.g.~printing (error) messages.
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   182
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   183
  \end{description}
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   184
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   185
  \begin{warn}
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   186
    When importing any of these theories, they should form the last
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   187
    items in an import list.  Since these theories adapt the code
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   188
    generator setup in a non-conservative fashion, strange effects may
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   189
    occur otherwise.
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   190
  \end{warn}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   191
\end{isamarkuptext}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   192
\isamarkuptrue%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   193
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   194
\isamarkupsubsection{Parametrising serialisation \label{sec:adaptation_mechanisms}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   195
}
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   196
\isamarkuptrue%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   197
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   198
\begin{isamarkuptext}%
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   199
Consider the following function and its corresponding SML code:%
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   200
\end{isamarkuptext}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   201
\isamarkuptrue%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   202
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   203
\isadelimquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   204
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   205
\endisadelimquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   206
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   207
\isatagquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   208
\isacommand{primrec}\isamarkupfalse%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   209
\ in{\isacharunderscore}interval\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymtimes}\ nat\ {\isasymRightarrow}\ nat\ {\isasymRightarrow}\ bool{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   210
\ \ {\isachardoublequoteopen}in{\isacharunderscore}interval\ {\isacharparenleft}k{\isacharcomma}\ l{\isacharparenright}\ n\ {\isasymlongleftrightarrow}\ k\ {\isasymle}\ n\ {\isasymand}\ n\ {\isasymle}\ l{\isachardoublequoteclose}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   211
\endisatagquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   212
{\isafoldquote}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   213
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   214
\isadelimquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   215
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   216
\endisadelimquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   217
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   218
\isadeliminvisible
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   219
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   220
\endisadeliminvisible
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   221
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   222
\isataginvisible
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   223
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   224
\endisataginvisible
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   225
{\isafoldinvisible}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   226
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   227
\isadeliminvisible
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   228
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   229
\endisadeliminvisible
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   230
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   231
\isadelimquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   232
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   233
\endisadelimquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   234
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   235
\isatagquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   236
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   237
\begin{isamarkuptext}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   238
\isatypewriter%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   239
\noindent%
34155
14aaccb399b3 Polishing up the English
paulson
parents: 33707
diff changeset
   240
\hspace*{0pt}structure Example :~sig\\
34179
5490151d1052 updated generated document sources
haftmann
parents: 34155
diff changeset
   241
\hspace*{0pt} ~datatype nat = Zero{\char95}nat | Suc of nat\\
34155
14aaccb399b3 Polishing up the English
paulson
parents: 33707
diff changeset
   242
\hspace*{0pt} ~datatype boola = True | False\\
14aaccb399b3 Polishing up the English
paulson
parents: 33707
diff changeset
   243
\hspace*{0pt} ~val anda :~boola -> boola -> boola\\
14aaccb399b3 Polishing up the English
paulson
parents: 33707
diff changeset
   244
\hspace*{0pt} ~val less{\char95}nat :~nat -> nat -> boola\\
14aaccb399b3 Polishing up the English
paulson
parents: 33707
diff changeset
   245
\hspace*{0pt} ~val less{\char95}eq{\char95}nat :~nat -> nat -> boola\\
14aaccb399b3 Polishing up the English
paulson
parents: 33707
diff changeset
   246
\hspace*{0pt} ~val in{\char95}interval :~nat * nat -> nat -> boola\\
14aaccb399b3 Polishing up the English
paulson
parents: 33707
diff changeset
   247
\hspace*{0pt}end = struct\\
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   248
\hspace*{0pt}\\
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   249
\hspace*{0pt}datatype nat = Zero{\char95}nat | Suc of nat;\\
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   250
\hspace*{0pt}\\
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   251
\hspace*{0pt}datatype boola = True | False;\\
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   252
\hspace*{0pt}\\
33707
68841fb382e0 dropped obsolete documentation; updated generated sources
haftmann
parents: 31206
diff changeset
   253
\hspace*{0pt}fun anda p True = p\\
34179
5490151d1052 updated generated document sources
haftmann
parents: 34155
diff changeset
   254
\hspace*{0pt} ~| anda p False = False\\
5490151d1052 updated generated document sources
haftmann
parents: 34155
diff changeset
   255
\hspace*{0pt} ~| anda True p = p\\
5490151d1052 updated generated document sources
haftmann
parents: 34155
diff changeset
   256
\hspace*{0pt} ~| anda False p = False;\\
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   257
\hspace*{0pt}\\
34179
5490151d1052 updated generated document sources
haftmann
parents: 34155
diff changeset
   258
\hspace*{0pt}fun less{\char95}nat m (Suc n) = less{\char95}eq{\char95}nat m n\\
5490151d1052 updated generated document sources
haftmann
parents: 34155
diff changeset
   259
\hspace*{0pt} ~| less{\char95}nat n Zero{\char95}nat = False\\
5490151d1052 updated generated document sources
haftmann
parents: 34155
diff changeset
   260
\hspace*{0pt}and less{\char95}eq{\char95}nat (Suc m) n = less{\char95}nat m n\\
5490151d1052 updated generated document sources
haftmann
parents: 34155
diff changeset
   261
\hspace*{0pt} ~| less{\char95}eq{\char95}nat Zero{\char95}nat n = True;\\
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   262
\hspace*{0pt}\\
34179
5490151d1052 updated generated document sources
haftmann
parents: 34155
diff changeset
   263
\hspace*{0pt}fun in{\char95}interval (k,~l) n = anda (less{\char95}eq{\char95}nat k n) (less{\char95}eq{\char95}nat n l);\\
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   264
\hspace*{0pt}\\
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   265
\hspace*{0pt}end;~(*struct Example*)%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   266
\end{isamarkuptext}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   267
\isamarkuptrue%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   268
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   269
\endisatagquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   270
{\isafoldquote}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   271
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   272
\isadelimquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   273
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   274
\endisadelimquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   275
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   276
\begin{isamarkuptext}%
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   277
\noindent Though this is correct code, it is a little bit
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   278
  unsatisfactory: boolean values and operators are materialised as
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   279
  distinguished entities with have nothing to do with the SML-built-in
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   280
  notion of \qt{bool}.  This results in less readable code;
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   281
  additionally, eager evaluation may cause programs to loop or break
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   282
  which would perfectly terminate when the existing SML \verb|bool| would be used.  To map the HOL \isa{bool} on SML \verb|bool|, we may use \qn{custom serialisations}:%
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   283
\end{isamarkuptext}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   284
\isamarkuptrue%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   285
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   286
\isadelimquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   287
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   288
\endisadelimquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   289
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   290
\isatagquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   291
\isacommand{code{\isacharunderscore}type}\isamarkupfalse%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   292
\ bool\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   293
\ \ {\isacharparenleft}SML\ {\isachardoublequoteopen}bool{\isachardoublequoteclose}{\isacharparenright}\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   294
\isacommand{code{\isacharunderscore}const}\isamarkupfalse%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   295
\ True\ \isakeyword{and}\ False\ \isakeyword{and}\ {\isachardoublequoteopen}op\ {\isasymand}{\isachardoublequoteclose}\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   296
\ \ {\isacharparenleft}SML\ {\isachardoublequoteopen}true{\isachardoublequoteclose}\ \isakeyword{and}\ {\isachardoublequoteopen}false{\isachardoublequoteclose}\ \isakeyword{and}\ {\isachardoublequoteopen}{\isacharunderscore}\ andalso\ {\isacharunderscore}{\isachardoublequoteclose}{\isacharparenright}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   297
\endisatagquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   298
{\isafoldquotett}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   299
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   300
\isadelimquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   301
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   302
\endisadelimquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   303
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   304
\begin{isamarkuptext}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   305
\noindent The \hyperlink{command.code-type}{\mbox{\isa{\isacommand{code{\isacharunderscore}type}}}} command takes a type constructor
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   306
  as arguments together with a list of custom serialisations.  Each
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   307
  custom serialisation starts with a target language identifier
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   308
  followed by an expression, which during code serialisation is
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   309
  inserted whenever the type constructor would occur.  For constants,
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   310
  \hyperlink{command.code-const}{\mbox{\isa{\isacommand{code{\isacharunderscore}const}}}} implements the corresponding mechanism.  Each
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   311
  ``\verb|_|'' in a serialisation expression is treated as a
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   312
  placeholder for the type constructor's (the constant's) arguments.%
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   313
\end{isamarkuptext}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   314
\isamarkuptrue%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   315
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   316
\isadelimquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   317
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   318
\endisadelimquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   319
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   320
\isatagquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   321
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   322
\begin{isamarkuptext}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   323
\isatypewriter%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   324
\noindent%
34155
14aaccb399b3 Polishing up the English
paulson
parents: 33707
diff changeset
   325
\hspace*{0pt}structure Example :~sig\\
34179
5490151d1052 updated generated document sources
haftmann
parents: 34155
diff changeset
   326
\hspace*{0pt} ~datatype nat = Zero{\char95}nat | Suc of nat\\
34155
14aaccb399b3 Polishing up the English
paulson
parents: 33707
diff changeset
   327
\hspace*{0pt} ~val less{\char95}nat :~nat -> nat -> bool\\
14aaccb399b3 Polishing up the English
paulson
parents: 33707
diff changeset
   328
\hspace*{0pt} ~val less{\char95}eq{\char95}nat :~nat -> nat -> bool\\
14aaccb399b3 Polishing up the English
paulson
parents: 33707
diff changeset
   329
\hspace*{0pt} ~val in{\char95}interval :~nat * nat -> nat -> bool\\
14aaccb399b3 Polishing up the English
paulson
parents: 33707
diff changeset
   330
\hspace*{0pt}end = struct\\
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   331
\hspace*{0pt}\\
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   332
\hspace*{0pt}datatype nat = Zero{\char95}nat | Suc of nat;\\
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   333
\hspace*{0pt}\\
34179
5490151d1052 updated generated document sources
haftmann
parents: 34155
diff changeset
   334
\hspace*{0pt}fun less{\char95}nat m (Suc n) = less{\char95}eq{\char95}nat m n\\
5490151d1052 updated generated document sources
haftmann
parents: 34155
diff changeset
   335
\hspace*{0pt} ~| less{\char95}nat n Zero{\char95}nat = false\\
5490151d1052 updated generated document sources
haftmann
parents: 34155
diff changeset
   336
\hspace*{0pt}and less{\char95}eq{\char95}nat (Suc m) n = less{\char95}nat m n\\
5490151d1052 updated generated document sources
haftmann
parents: 34155
diff changeset
   337
\hspace*{0pt} ~| less{\char95}eq{\char95}nat Zero{\char95}nat n = true;\\
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   338
\hspace*{0pt}\\
34179
5490151d1052 updated generated document sources
haftmann
parents: 34155
diff changeset
   339
\hspace*{0pt}fun in{\char95}interval (k,~l) n = (less{\char95}eq{\char95}nat k n) andalso (less{\char95}eq{\char95}nat n l);\\
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   340
\hspace*{0pt}\\
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   341
\hspace*{0pt}end;~(*struct Example*)%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   342
\end{isamarkuptext}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   343
\isamarkuptrue%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   344
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   345
\endisatagquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   346
{\isafoldquote}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   347
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   348
\isadelimquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   349
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   350
\endisadelimquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   351
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   352
\begin{isamarkuptext}%
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   353
\noindent This still is not perfect: the parentheses around the
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   354
  \qt{andalso} expression are superfluous.  Though the serialiser by
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   355
  no means attempts to imitate the rich Isabelle syntax framework, it
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   356
  provides some common idioms, notably associative infixes with
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   357
  precedences which may be used here:%
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   358
\end{isamarkuptext}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   359
\isamarkuptrue%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   360
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   361
\isadelimquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   362
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   363
\endisadelimquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   364
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   365
\isatagquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   366
\isacommand{code{\isacharunderscore}const}\isamarkupfalse%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   367
\ {\isachardoublequoteopen}op\ {\isasymand}{\isachardoublequoteclose}\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   368
\ \ {\isacharparenleft}SML\ \isakeyword{infixl}\ {\isadigit{1}}\ {\isachardoublequoteopen}andalso{\isachardoublequoteclose}{\isacharparenright}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   369
\endisatagquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   370
{\isafoldquotett}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   371
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   372
\isadelimquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   373
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   374
\endisadelimquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   375
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   376
\isadelimquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   377
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   378
\endisadelimquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   379
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   380
\isatagquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   381
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   382
\begin{isamarkuptext}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   383
\isatypewriter%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   384
\noindent%
34155
14aaccb399b3 Polishing up the English
paulson
parents: 33707
diff changeset
   385
\hspace*{0pt}structure Example :~sig\\
34179
5490151d1052 updated generated document sources
haftmann
parents: 34155
diff changeset
   386
\hspace*{0pt} ~datatype nat = Zero{\char95}nat | Suc of nat\\
34155
14aaccb399b3 Polishing up the English
paulson
parents: 33707
diff changeset
   387
\hspace*{0pt} ~val less{\char95}nat :~nat -> nat -> bool\\
14aaccb399b3 Polishing up the English
paulson
parents: 33707
diff changeset
   388
\hspace*{0pt} ~val less{\char95}eq{\char95}nat :~nat -> nat -> bool\\
14aaccb399b3 Polishing up the English
paulson
parents: 33707
diff changeset
   389
\hspace*{0pt} ~val in{\char95}interval :~nat * nat -> nat -> bool\\
14aaccb399b3 Polishing up the English
paulson
parents: 33707
diff changeset
   390
\hspace*{0pt}end = struct\\
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   391
\hspace*{0pt}\\
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   392
\hspace*{0pt}datatype nat = Zero{\char95}nat | Suc of nat;\\
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   393
\hspace*{0pt}\\
34179
5490151d1052 updated generated document sources
haftmann
parents: 34155
diff changeset
   394
\hspace*{0pt}fun less{\char95}nat m (Suc n) = less{\char95}eq{\char95}nat m n\\
5490151d1052 updated generated document sources
haftmann
parents: 34155
diff changeset
   395
\hspace*{0pt} ~| less{\char95}nat n Zero{\char95}nat = false\\
5490151d1052 updated generated document sources
haftmann
parents: 34155
diff changeset
   396
\hspace*{0pt}and less{\char95}eq{\char95}nat (Suc m) n = less{\char95}nat m n\\
5490151d1052 updated generated document sources
haftmann
parents: 34155
diff changeset
   397
\hspace*{0pt} ~| less{\char95}eq{\char95}nat Zero{\char95}nat n = true;\\
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   398
\hspace*{0pt}\\
34179
5490151d1052 updated generated document sources
haftmann
parents: 34155
diff changeset
   399
\hspace*{0pt}fun in{\char95}interval (k,~l) n = less{\char95}eq{\char95}nat k n andalso less{\char95}eq{\char95}nat n l;\\
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   400
\hspace*{0pt}\\
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   401
\hspace*{0pt}end;~(*struct Example*)%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   402
\end{isamarkuptext}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   403
\isamarkuptrue%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   404
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   405
\endisatagquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   406
{\isafoldquote}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   407
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   408
\isadelimquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   409
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   410
\endisadelimquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   411
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   412
\begin{isamarkuptext}%
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   413
\noindent The attentive reader may ask how we assert that no
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   414
  generated code will accidentally overwrite.  For this reason the
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   415
  serialiser has an internal table of identifiers which have to be
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   416
  avoided to be used for new declarations.  Initially, this table
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   417
  typically contains the keywords of the target language.  It can be
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   418
  extended manually, thus avoiding accidental overwrites, using the
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   419
  \hyperlink{command.code-reserved}{\mbox{\isa{\isacommand{code{\isacharunderscore}reserved}}}} command:%
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   420
\end{isamarkuptext}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   421
\isamarkuptrue%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   422
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   423
\isadelimquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   424
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   425
\endisadelimquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   426
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   427
\isatagquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   428
\isacommand{code{\isacharunderscore}reserved}\isamarkupfalse%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   429
\ {\isachardoublequoteopen}{\isasymSML}{\isachardoublequoteclose}\ bool\ true\ false\ andalso%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   430
\endisatagquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   431
{\isafoldquote}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   432
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   433
\isadelimquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   434
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   435
\endisadelimquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   436
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   437
\begin{isamarkuptext}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   438
\noindent Next, we try to map HOL pairs to SML pairs, using the
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   439
  infix ``\verb|*|'' type constructor and parentheses:%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   440
\end{isamarkuptext}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   441
\isamarkuptrue%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   442
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   443
\isadeliminvisible
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   444
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   445
\endisadeliminvisible
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   446
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   447
\isataginvisible
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   448
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   449
\endisataginvisible
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   450
{\isafoldinvisible}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   451
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   452
\isadeliminvisible
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   453
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   454
\endisadeliminvisible
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   455
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   456
\isadelimquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   457
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   458
\endisadelimquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   459
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   460
\isatagquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   461
\isacommand{code{\isacharunderscore}type}\isamarkupfalse%
37836
2bcce92be291 adjusted; fixed typo
haftmann
parents: 34179
diff changeset
   462
\ prod\isanewline
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   463
\ \ {\isacharparenleft}SML\ \isakeyword{infix}\ {\isadigit{2}}\ {\isachardoublequoteopen}{\isacharasterisk}{\isachardoublequoteclose}{\isacharparenright}\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   464
\isacommand{code{\isacharunderscore}const}\isamarkupfalse%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   465
\ Pair\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   466
\ \ {\isacharparenleft}SML\ {\isachardoublequoteopen}{\isacharbang}{\isacharparenleft}{\isacharparenleft}{\isacharunderscore}{\isacharparenright}{\isacharcomma}{\isacharslash}\ {\isacharparenleft}{\isacharunderscore}{\isacharparenright}{\isacharparenright}{\isachardoublequoteclose}{\isacharparenright}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   467
\endisatagquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   468
{\isafoldquotett}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   469
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   470
\isadelimquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   471
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   472
\endisadelimquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   473
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   474
\begin{isamarkuptext}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   475
\noindent The initial bang ``\verb|!|'' tells the serialiser
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   476
  never to put parentheses around the whole expression (they are
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   477
  already present), while the parentheses around argument place
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   478
  holders tell not to put parentheses around the arguments.  The slash
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   479
  ``\verb|/|'' (followed by arbitrary white space) inserts a
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   480
  space which may be used as a break if necessary during pretty
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   481
  printing.
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   482
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   483
  These examples give a glimpse what mechanisms custom serialisations
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   484
  provide; however their usage requires careful thinking in order not
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   485
  to introduce inconsistencies -- or, in other words: custom
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   486
  serialisations are completely axiomatic.
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   487
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   488
  A further noteworthy details is that any special character in a
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   489
  custom serialisation may be quoted using ``\verb|'|''; thus,
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   490
  in ``\verb|fn '_ => _|'' the first ``\verb|_|'' is a
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   491
  proper underscore while the second ``\verb|_|'' is a
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   492
  placeholder.%
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   493
\end{isamarkuptext}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   494
\isamarkuptrue%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   495
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   496
\isamarkupsubsection{\isa{Haskell} serialisation%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   497
}
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   498
\isamarkuptrue%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   499
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   500
\begin{isamarkuptext}%
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   501
For convenience, the default \isa{HOL} setup for \isa{Haskell}
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   502
  maps the \isa{eq} class to its counterpart in \isa{Haskell},
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   503
  giving custom serialisations for the class \isa{eq} (by command
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   504
  \hyperlink{command.code-class}{\mbox{\isa{\isacommand{code{\isacharunderscore}class}}}}) and its operation \isa{eq{\isacharunderscore}class{\isachardot}eq}%
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   505
\end{isamarkuptext}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   506
\isamarkuptrue%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   507
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   508
\isadelimquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   509
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   510
\endisadelimquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   511
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   512
\isatagquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   513
\isacommand{code{\isacharunderscore}class}\isamarkupfalse%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   514
\ eq\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   515
\ \ {\isacharparenleft}Haskell\ {\isachardoublequoteopen}Eq{\isachardoublequoteclose}{\isacharparenright}\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   516
\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   517
\isacommand{code{\isacharunderscore}const}\isamarkupfalse%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   518
\ {\isachardoublequoteopen}op\ {\isacharequal}{\isachardoublequoteclose}\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   519
\ \ {\isacharparenleft}Haskell\ \isakeyword{infixl}\ {\isadigit{4}}\ {\isachardoublequoteopen}{\isacharequal}{\isacharequal}{\isachardoublequoteclose}{\isacharparenright}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   520
\endisatagquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   521
{\isafoldquotett}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   522
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   523
\isadelimquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   524
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   525
\endisadelimquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   526
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   527
\begin{isamarkuptext}%
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   528
\noindent A problem now occurs whenever a type which is an instance
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   529
  of \isa{eq} in \isa{HOL} is mapped on a \isa{Haskell}-built-in type which is also an instance of \isa{Haskell}
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   530
  \isa{Eq}:%
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   531
\end{isamarkuptext}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   532
\isamarkuptrue%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   533
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   534
\isadelimquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   535
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   536
\endisadelimquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   537
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   538
\isatagquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   539
\isacommand{typedecl}\isamarkupfalse%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   540
\ bar\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   541
\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   542
\isacommand{instantiation}\isamarkupfalse%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   543
\ bar\ {\isacharcolon}{\isacharcolon}\ eq\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   544
\isakeyword{begin}\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   545
\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   546
\isacommand{definition}\isamarkupfalse%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   547
\ {\isachardoublequoteopen}eq{\isacharunderscore}class{\isachardot}eq\ {\isacharparenleft}x{\isasymColon}bar{\isacharparenright}\ y\ {\isasymlongleftrightarrow}\ x\ {\isacharequal}\ y{\isachardoublequoteclose}\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   548
\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   549
\isacommand{instance}\isamarkupfalse%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   550
\ \isacommand{by}\isamarkupfalse%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   551
\ default\ {\isacharparenleft}simp\ add{\isacharcolon}\ eq{\isacharunderscore}bar{\isacharunderscore}def{\isacharparenright}\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   552
\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   553
\isacommand{end}\isamarkupfalse%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   554
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   555
\endisatagquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   556
{\isafoldquote}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   557
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   558
\isadelimquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   559
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   560
\endisadelimquote
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   561
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   562
\isadelimquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   563
\ %
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   564
\endisadelimquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   565
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   566
\isatagquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   567
\isacommand{code{\isacharunderscore}type}\isamarkupfalse%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   568
\ bar\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   569
\ \ {\isacharparenleft}Haskell\ {\isachardoublequoteopen}Integer{\isachardoublequoteclose}{\isacharparenright}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   570
\endisatagquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   571
{\isafoldquotett}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   572
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   573
\isadelimquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   574
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   575
\endisadelimquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   576
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   577
\begin{isamarkuptext}%
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   578
\noindent The code generator would produce an additional instance,
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   579
  which of course is rejected by the \isa{Haskell} compiler.  To
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   580
  suppress this additional instance, use \isa{code{\isacharunderscore}instance}:%
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   581
\end{isamarkuptext}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   582
\isamarkuptrue%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   583
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   584
\isadelimquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   585
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   586
\endisadelimquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   587
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   588
\isatagquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   589
\isacommand{code{\isacharunderscore}instance}\isamarkupfalse%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   590
\ bar\ {\isacharcolon}{\isacharcolon}\ eq\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   591
\ \ {\isacharparenleft}Haskell\ {\isacharminus}{\isacharparenright}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   592
\endisatagquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   593
{\isafoldquotett}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   594
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   595
\isadelimquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   596
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   597
\endisadelimquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   598
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   599
\isamarkupsubsection{Enhancing the target language context \label{sec:include}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   600
}
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   601
\isamarkuptrue%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   602
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   603
\begin{isamarkuptext}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   604
In rare cases it is necessary to \emph{enrich} the context of a
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   605
  target language; this is accomplished using the \hyperlink{command.code-include}{\mbox{\isa{\isacommand{code{\isacharunderscore}include}}}} command:%
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   606
\end{isamarkuptext}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   607
\isamarkuptrue%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   608
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   609
\isadelimquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   610
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   611
\endisadelimquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   612
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   613
\isatagquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   614
\isacommand{code{\isacharunderscore}include}\isamarkupfalse%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   615
\ Haskell\ {\isachardoublequoteopen}Errno{\isachardoublequoteclose}\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   616
{\isacharverbatimopen}errno\ i\ {\isacharequal}\ error\ {\isacharparenleft}{\isachardoublequote}Error\ number{\isacharcolon}\ {\isachardoublequote}\ {\isacharplus}{\isacharplus}\ show\ i{\isacharparenright}{\isacharverbatimclose}\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   617
\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   618
\isacommand{code{\isacharunderscore}reserved}\isamarkupfalse%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   619
\ Haskell\ Errno%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   620
\endisatagquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   621
{\isafoldquotett}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   622
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   623
\isadelimquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   624
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   625
\endisadelimquotett
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   626
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   627
\begin{isamarkuptext}%
38450
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   628
\noindent Such named \isa{include}s are then prepended to every
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   629
  generated code.  Inspect such code in order to find out how
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   630
  \hyperlink{command.code-include}{\mbox{\isa{\isacommand{code{\isacharunderscore}include}}}} behaves with respect to a particular
ada5814c9d87 tuned whitespace
haftmann
parents: 37836
diff changeset
   631
  target language.%
31050
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   632
\end{isamarkuptext}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   633
\isamarkuptrue%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   634
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   635
\isadelimtheory
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   636
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   637
\endisadelimtheory
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   638
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   639
\isatagtheory
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   640
\isacommand{end}\isamarkupfalse%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   641
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   642
\endisatagtheory
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   643
{\isafoldtheory}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   644
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   645
\isadelimtheory
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   646
%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   647
\endisadelimtheory
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   648
\isanewline
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   649
\end{isabellebody}%
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   650
%%% Local Variables:
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   651
%%% mode: latex
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   652
%%% TeX-master: "root"
555b56b66fcf adaptation replaces adaption
haftmann
parents:
diff changeset
   653
%%% End: