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