author | wenzelm |
Mon, 15 Jul 2013 20:13:30 +0200 | |
changeset 52665 | 5f817bad850a |
parent 52378 | 08dbf9ff2140 |
child 52742 | e7296939fec2 |
permissions | -rw-r--r-- |
31050 | 1 |
theory Adaptation |
28213 | 2 |
imports Setup |
3 |
begin |
|
4 |
||
40351 | 5 |
setup %invisible {* Code_Target.extend_target ("\<SML>", ("SML", K I)) |
6 |
#> Code_Target.extend_target ("\<SMLdummy>", ("Haskell", K I)) *} |
|
28561 | 7 |
|
31050 | 8 |
section {* Adaptation to target languages \label{sec:adaptation} *} |
28419 | 9 |
|
28561 | 10 |
subsection {* Adapting code generation *} |
11 |
||
12 |
text {* |
|
13 |
The aspects of code generation introduced so far have two aspects |
|
14 |
in common: |
|
15 |
||
16 |
\begin{itemize} |
|
38450 | 17 |
|
18 |
\item They act uniformly, without reference to a specific target |
|
19 |
language. |
|
20 |
||
28561 | 21 |
\item They are \emph{safe} in the sense that as long as you trust |
22 |
the code generator meta theory and implementation, you cannot |
|
38450 | 23 |
produce programs that yield results which are not derivable in |
24 |
the logic. |
|
25 |
||
28561 | 26 |
\end{itemize} |
27 |
||
38450 | 28 |
\noindent In this section we will introduce means to \emph{adapt} |
29 |
the serialiser to a specific target language, i.e.~to print program |
|
30 |
fragments in a way which accommodates \qt{already existing} |
|
31 |
ingredients of a target language environment, for three reasons: |
|
28561 | 32 |
|
33 |
\begin{itemize} |
|
28593 | 34 |
\item improving readability and aesthetics of generated code |
28561 | 35 |
\item gaining efficiency |
36 |
\item interface with language parts which have no direct counterpart |
|
37 |
in @{text "HOL"} (say, imperative data structures) |
|
38 |
\end{itemize} |
|
39 |
||
40 |
\noindent Generally, you should avoid using those features yourself |
|
41 |
\emph{at any cost}: |
|
42 |
||
43 |
\begin{itemize} |
|
38450 | 44 |
|
45 |
\item The safe configuration methods act uniformly on every target |
|
46 |
language, whereas for adaptation you have to treat each target |
|
47 |
language separately. |
|
48 |
||
49 |
\item Application is extremely tedious since there is no |
|
50 |
abstraction which would allow for a static check, making it easy |
|
51 |
to produce garbage. |
|
52 |
||
34155 | 53 |
\item Subtle errors can be introduced unconsciously. |
38450 | 54 |
|
28561 | 55 |
\end{itemize} |
56 |
||
38450 | 57 |
\noindent However, even if you ought refrain from setting up |
51162 | 58 |
adaptation yourself, already @{text "HOL"} comes with some |
38450 | 59 |
reasonable default adaptations (say, using target language list |
60 |
syntax). There also some common adaptation cases which you can |
|
61 |
setup by importing particular library theories. In order to |
|
62 |
understand these, we provide some clues here; these however are not |
|
63 |
supposed to replace a careful study of the sources. |
|
28561 | 64 |
*} |
65 |
||
38450 | 66 |
|
31050 | 67 |
subsection {* The adaptation principle *} |
28561 | 68 |
|
69 |
text {* |
|
38450 | 70 |
Figure \ref{fig:adaptation} illustrates what \qt{adaptation} is |
71 |
conceptually supposed to be: |
|
28601 | 72 |
|
73 |
\begin{figure}[here] |
|
48954
c548d26daa8c
avoid clash with generated Adaptation.tex on case-insensible file-systems;
wenzelm
parents:
48951
diff
changeset
|
74 |
\includegraphics{adapt} |
31050 | 75 |
\caption{The adaptation principle} |
76 |
\label{fig:adaptation} |
|
28601 | 77 |
\end{figure} |
78 |
||
79 |
\noindent In the tame view, code generation acts as broker between |
|
38450 | 80 |
@{text logic}, @{text "intermediate language"} and @{text "target |
81 |
language"} by means of @{text translation} and @{text |
|
82 |
serialisation}; for the latter, the serialiser has to observe the |
|
83 |
structure of the @{text language} itself plus some @{text reserved} |
|
84 |
keywords which have to be avoided for generated code. However, if |
|
85 |
you consider @{text adaptation} mechanisms, the code generated by |
|
86 |
the serializer is just the tip of the iceberg: |
|
28601 | 87 |
|
88 |
\begin{itemize} |
|
38450 | 89 |
|
28635 | 90 |
\item @{text serialisation} can be \emph{parametrised} such that |
91 |
logical entities are mapped to target-specific ones |
|
38450 | 92 |
(e.g. target-specific list syntax, see also |
93 |
\secref{sec:adaptation_mechanisms}) |
|
94 |
||
28635 | 95 |
\item Such parametrisations can involve references to a |
38450 | 96 |
target-specific standard @{text library} (e.g. using the @{text |
97 |
Haskell} @{verbatim Maybe} type instead of the @{text HOL} |
|
98 |
@{type "option"} type); if such are used, the corresponding |
|
99 |
identifiers (in our example, @{verbatim Maybe}, @{verbatim |
|
100 |
Nothing} and @{verbatim Just}) also have to be considered @{text |
|
101 |
reserved}. |
|
102 |
||
28635 | 103 |
\item Even more, the user can enrich the library of the |
38450 | 104 |
target-language by providing code snippets (\qt{@{text |
105 |
"includes"}}) which are prepended to any generated code (see |
|
106 |
\secref{sec:include}); this typically also involves further |
|
107 |
@{text reserved} identifiers. |
|
108 |
||
28601 | 109 |
\end{itemize} |
28635 | 110 |
|
38450 | 111 |
\noindent As figure \ref{fig:adaptation} illustrates, all these |
112 |
adaptation mechanisms have to act consistently; it is at the |
|
113 |
discretion of the user to take care for this. |
|
28561 | 114 |
*} |
115 |
||
31050 | 116 |
subsection {* Common adaptation patterns *} |
28419 | 117 |
|
118 |
text {* |
|
28428 | 119 |
The @{theory HOL} @{theory Main} theory already provides a code |
38450 | 120 |
generator setup which should be suitable for most applications. |
121 |
Common extensions and modifications are available by certain |
|
52665
5f817bad850a
prefer @{file} references that are actually checked;
wenzelm
parents:
52378
diff
changeset
|
122 |
theories in @{file "~~/src/HOL/Library"}; beside being useful in |
38450 | 123 |
applications, they may serve as a tutorial for customising the code |
124 |
generator setup (see below \secref{sec:adaptation_mechanisms}). |
|
28419 | 125 |
|
126 |
\begin{description} |
|
127 |
||
51143
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
48985
diff
changeset
|
128 |
\item[@{theory "Code_Numeral"}] provides additional numeric |
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
48985
diff
changeset
|
129 |
types @{typ integer} and @{typ natural} isomorphic to types |
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
48985
diff
changeset
|
130 |
@{typ int} and @{typ nat} respectively. Type @{typ integer} |
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
48985
diff
changeset
|
131 |
is mapped to target-language built-in integers; @{typ natural} |
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
48985
diff
changeset
|
132 |
is implemented as abstract type over @{typ integer}. |
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
48985
diff
changeset
|
133 |
Useful for code setups which involve e.g.~indexing |
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
48985
diff
changeset
|
134 |
of target-language arrays. Part of @{text "HOL-Main"}. |
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
48985
diff
changeset
|
135 |
|
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
48985
diff
changeset
|
136 |
\item[@{text "Code_Target_Int"}] implements type @{typ int} |
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
48985
diff
changeset
|
137 |
by @{typ integer} and thus by target-language built-in integers. |
38450 | 138 |
|
51171
e8b2d90da499
corrected and clarified Code_Binary_Nat vs. Code_Target_Nat
haftmann
parents:
51162
diff
changeset
|
139 |
\item[@{text "Code_Binary_Nat"}] implements type |
51143
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
48985
diff
changeset
|
140 |
@{typ nat} using a binary rather than a linear representation, |
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
48985
diff
changeset
|
141 |
which yields a considerable speedup for computations. |
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
48985
diff
changeset
|
142 |
Pattern matching with @{term "0\<Colon>nat"} / @{const "Suc"} is eliminated |
51171
e8b2d90da499
corrected and clarified Code_Binary_Nat vs. Code_Target_Nat
haftmann
parents:
51162
diff
changeset
|
143 |
by a preprocessor.\label{abstract_nat} |
51143
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
48985
diff
changeset
|
144 |
|
51171
e8b2d90da499
corrected and clarified Code_Binary_Nat vs. Code_Target_Nat
haftmann
parents:
51162
diff
changeset
|
145 |
\item[@{text "Code_Target_Nat"}] implements type @{typ nat} |
e8b2d90da499
corrected and clarified Code_Binary_Nat vs. Code_Target_Nat
haftmann
parents:
51162
diff
changeset
|
146 |
by @{typ integer} and thus by target-language built-in integers. |
e8b2d90da499
corrected and clarified Code_Binary_Nat vs. Code_Target_Nat
haftmann
parents:
51162
diff
changeset
|
147 |
Pattern matching with @{term "0\<Colon>nat"} / @{const "Suc"} is eliminated |
e8b2d90da499
corrected and clarified Code_Binary_Nat vs. Code_Target_Nat
haftmann
parents:
51162
diff
changeset
|
148 |
by a preprocessor. |
51143
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
48985
diff
changeset
|
149 |
|
51162 | 150 |
\item[@{text "Code_Target_Numeral"}] is a convenience theory |
51143
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
48985
diff
changeset
|
151 |
containing both @{text "Code_Target_Nat"} and |
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
48985
diff
changeset
|
152 |
@{text "Code_Target_Int"}. |
38450 | 153 |
|
51143
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
48985
diff
changeset
|
154 |
\item[@{text "Code_Char"}] represents @{text HOL} characters by |
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
48985
diff
changeset
|
155 |
character literals in target languages. |
38450 | 156 |
|
157 |
\item[@{theory "String"}] provides an additional datatype @{typ |
|
158 |
String.literal} which is isomorphic to strings; @{typ |
|
159 |
String.literal}s are mapped to target-language strings. Useful |
|
160 |
for code setups which involve e.g.~printing (error) messages. |
|
46519 | 161 |
Part of @{text "HOL-Main"}. |
28419 | 162 |
|
51162 | 163 |
\item[@{theory "IArray"}] provides a type @{typ "'a iarray"} |
164 |
isomorphic to lists but implemented by (effectively immutable) |
|
165 |
arrays \emph{in SML only}. |
|
28419 | 166 |
|
51162 | 167 |
\end{description} |
28419 | 168 |
*} |
169 |
||
170 |
||
31050 | 171 |
subsection {* Parametrising serialisation \label{sec:adaptation_mechanisms} *} |
28419 | 172 |
|
173 |
text {* |
|
38450 | 174 |
Consider the following function and its corresponding SML code: |
28419 | 175 |
*} |
176 |
||
28564 | 177 |
primrec %quote in_interval :: "nat \<times> nat \<Rightarrow> nat \<Rightarrow> bool" where |
28419 | 178 |
"in_interval (k, l) n \<longleftrightarrow> k \<le> n \<and> n \<le> l" |
28447 | 179 |
(*<*) |
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
180 |
code_printing %invisible |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
181 |
type_constructor bool \<rightharpoonup> (SML) |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
182 |
| constant True \<rightharpoonup> (SML) |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
183 |
| constant False \<rightharpoonup> (SML) |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
184 |
| constant HOL.conj \<rightharpoonup> (SML) |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
185 |
| constant Not \<rightharpoonup> (SML) |
28447 | 186 |
(*>*) |
39745 | 187 |
text %quotetypewriter {* |
39683 | 188 |
@{code_stmts in_interval (SML)} |
39664
0afaf89ab591
more canonical type setting of type writer code examples
haftmann
parents:
39643
diff
changeset
|
189 |
*} |
28419 | 190 |
|
191 |
text {* |
|
38450 | 192 |
\noindent Though this is correct code, it is a little bit |
193 |
unsatisfactory: boolean values and operators are materialised as |
|
194 |
distinguished entities with have nothing to do with the SML-built-in |
|
195 |
notion of \qt{bool}. This results in less readable code; |
|
196 |
additionally, eager evaluation may cause programs to loop or break |
|
197 |
which would perfectly terminate when the existing SML @{verbatim |
|
198 |
"bool"} would be used. To map the HOL @{typ bool} on SML @{verbatim |
|
199 |
"bool"}, we may use \qn{custom serialisations}: |
|
28419 | 200 |
*} |
201 |
||
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
202 |
code_printing %quotett |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
203 |
type_constructor bool \<rightharpoonup> (SML) "bool" |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
204 |
| constant True \<rightharpoonup> (SML) "true" |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
205 |
| constant False \<rightharpoonup> (SML) "false" |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
206 |
| constant HOL.conj \<rightharpoonup> (SML) "_ andalso _" |
28213 | 207 |
|
28419 | 208 |
text {* |
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
209 |
\noindent The @{command_def code_printing} command takes a series |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
210 |
of symbols (contants, type constructor, \ldots) |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
211 |
together with target-specific custom serialisations. Each |
38450 | 212 |
custom serialisation starts with a target language identifier |
213 |
followed by an expression, which during code serialisation is |
|
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
214 |
inserted whenever the type constructor would occur. Each |
38450 | 215 |
``@{verbatim "_"}'' in a serialisation expression is treated as a |
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
216 |
placeholder for the constant's or the type constructor's arguments. |
28419 | 217 |
*} |
218 |
||
39745 | 219 |
text %quotetypewriter {* |
39683 | 220 |
@{code_stmts in_interval (SML)} |
39664
0afaf89ab591
more canonical type setting of type writer code examples
haftmann
parents:
39643
diff
changeset
|
221 |
*} |
28419 | 222 |
|
223 |
text {* |
|
38450 | 224 |
\noindent This still is not perfect: the parentheses around the |
225 |
\qt{andalso} expression are superfluous. Though the serialiser by |
|
226 |
no means attempts to imitate the rich Isabelle syntax framework, it |
|
227 |
provides some common idioms, notably associative infixes with |
|
228 |
precedences which may be used here: |
|
28419 | 229 |
*} |
230 |
||
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
231 |
code_printing %quotett |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
232 |
constant HOL.conj \<rightharpoonup> (SML) infixl 1 "andalso" |
28419 | 233 |
|
39745 | 234 |
text %quotetypewriter {* |
39683 | 235 |
@{code_stmts in_interval (SML)} |
39664
0afaf89ab591
more canonical type setting of type writer code examples
haftmann
parents:
39643
diff
changeset
|
236 |
*} |
28419 | 237 |
|
238 |
text {* |
|
38450 | 239 |
\noindent The attentive reader may ask how we assert that no |
240 |
generated code will accidentally overwrite. For this reason the |
|
241 |
serialiser has an internal table of identifiers which have to be |
|
242 |
avoided to be used for new declarations. Initially, this table |
|
243 |
typically contains the keywords of the target language. It can be |
|
244 |
extended manually, thus avoiding accidental overwrites, using the |
|
38505 | 245 |
@{command_def "code_reserved"} command: |
28561 | 246 |
*} |
247 |
||
40351 | 248 |
code_reserved %quote "\<SMLdummy>" bool true false andalso |
28561 | 249 |
|
250 |
text {* |
|
28447 | 251 |
\noindent Next, we try to map HOL pairs to SML pairs, using the |
28419 | 252 |
infix ``@{verbatim "*"}'' type constructor and parentheses: |
253 |
*} |
|
28447 | 254 |
(*<*) |
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
255 |
code_printing %invisible |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
256 |
type_constructor prod \<rightharpoonup> (SML) |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
257 |
| constant Pair \<rightharpoonup> (SML) |
28447 | 258 |
(*>*) |
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
259 |
code_printing %quotett |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
260 |
type_constructor prod \<rightharpoonup> (SML) infix 2 "*" |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
261 |
| constant Pair \<rightharpoonup> (SML) "!((_),/ (_))" |
28419 | 262 |
|
263 |
text {* |
|
28593 | 264 |
\noindent The initial bang ``@{verbatim "!"}'' tells the serialiser |
38450 | 265 |
never to put parentheses around the whole expression (they are |
266 |
already present), while the parentheses around argument place |
|
267 |
holders tell not to put parentheses around the arguments. The slash |
|
268 |
``@{verbatim "/"}'' (followed by arbitrary white space) inserts a |
|
269 |
space which may be used as a break if necessary during pretty |
|
270 |
printing. |
|
28419 | 271 |
|
38450 | 272 |
These examples give a glimpse what mechanisms custom serialisations |
273 |
provide; however their usage requires careful thinking in order not |
|
274 |
to introduce inconsistencies -- or, in other words: custom |
|
275 |
serialisations are completely axiomatic. |
|
28419 | 276 |
|
39643 | 277 |
A further noteworthy detail is that any special character in a |
38450 | 278 |
custom serialisation may be quoted using ``@{verbatim "'"}''; thus, |
279 |
in ``@{verbatim "fn '_ => _"}'' the first ``@{verbatim "_"}'' is a |
|
280 |
proper underscore while the second ``@{verbatim "_"}'' is a |
|
281 |
placeholder. |
|
28419 | 282 |
*} |
283 |
||
284 |
||
285 |
subsection {* @{text Haskell} serialisation *} |
|
286 |
||
287 |
text {* |
|
38450 | 288 |
For convenience, the default @{text HOL} setup for @{text Haskell} |
39063 | 289 |
maps the @{class equal} class to its counterpart in @{text Haskell}, |
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
290 |
giving custom serialisations for the class @{class equal} |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
291 |
and its operation @{const [source] HOL.equal}. |
28419 | 292 |
*} |
293 |
||
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
294 |
code_printing %quotett |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
295 |
type_class equal \<rightharpoonup> (Haskell) "Eq" |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
296 |
| constant HOL.equal \<rightharpoonup> (Haskell) infixl 4 "==" |
28419 | 297 |
|
298 |
text {* |
|
38450 | 299 |
\noindent A problem now occurs whenever a type which is an instance |
39063 | 300 |
of @{class equal} in @{text HOL} is mapped on a @{text |
38450 | 301 |
Haskell}-built-in type which is also an instance of @{text Haskell} |
302 |
@{text Eq}: |
|
28419 | 303 |
*} |
304 |
||
28564 | 305 |
typedecl %quote bar |
28419 | 306 |
|
39063 | 307 |
instantiation %quote bar :: equal |
28419 | 308 |
begin |
309 |
||
39063 | 310 |
definition %quote "HOL.equal (x\<Colon>bar) y \<longleftrightarrow> x = y" |
28419 | 311 |
|
39063 | 312 |
instance %quote by default (simp add: equal_bar_def) |
28213 | 313 |
|
30880 | 314 |
end %quote (*<*) |
315 |
||
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
316 |
(*>*) code_printing %quotett |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
317 |
type_constructor bar \<rightharpoonup> (Haskell) "Integer" |
28419 | 318 |
|
319 |
text {* |
|
38450 | 320 |
\noindent The code generator would produce an additional instance, |
321 |
which of course is rejected by the @{text Haskell} compiler. To |
|
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
322 |
suppress this additional instance: |
28419 | 323 |
*} |
324 |
||
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
325 |
code_printing %quotett |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
326 |
class_instance bar :: "HOL.equal" \<rightharpoonup> (Haskell) - |
28419 | 327 |
|
28561 | 328 |
|
28635 | 329 |
subsection {* Enhancing the target language context \label{sec:include} *} |
28561 | 330 |
|
331 |
text {* |
|
28593 | 332 |
In rare cases it is necessary to \emph{enrich} the context of a |
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
333 |
target language; this can also be accomplished using the @{command |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
334 |
"code_printing"} command: |
28561 | 335 |
*} |
336 |
||
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
337 |
code_printing %quotett |
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
338 |
code_module "Errno" \<rightharpoonup> (Haskell) {*errno i = error ("Error number: " ++ show i)*} |
28561 | 339 |
|
39745 | 340 |
code_reserved %quotett Haskell Errno |
28561 | 341 |
|
342 |
text {* |
|
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
343 |
\noindent Such named modules are then prepended to every |
38450 | 344 |
generated code. Inspect such code in order to find out how |
52378
08dbf9ff2140
documentation on code_printing and code_identifier
haftmann
parents:
51172
diff
changeset
|
345 |
this behaves with respect to a particular |
38450 | 346 |
target language. |
28561 | 347 |
*} |
348 |
||
28419 | 349 |
end |
46519 | 350 |