author | bulwahn |
Tue, 08 May 2012 14:31:03 +0200 | |
changeset 47893 | 4cf901b1089a |
parent 46523 | 7ca897381b26 |
child 48501 | e59778bc71a0 |
permissions | -rw-r--r-- |
28447 | 1 |
% |
2 |
\begin{isabellebody}% |
|
3 |
\def\isabellecontext{Further}% |
|
4 |
% |
|
5 |
\isadelimtheory |
|
6 |
% |
|
7 |
\endisadelimtheory |
|
8 |
% |
|
9 |
\isatagtheory |
|
10 |
\isacommand{theory}\isamarkupfalse% |
|
11 |
\ Further\isanewline |
|
12 |
\isakeyword{imports}\ Setup\isanewline |
|
13 |
\isakeyword{begin}% |
|
14 |
\endisatagtheory |
|
15 |
{\isafoldtheory}% |
|
16 |
% |
|
17 |
\isadelimtheory |
|
18 |
% |
|
19 |
\endisadelimtheory |
|
20 |
% |
|
21 |
\isamarkupsection{Further issues \label{sec:further}% |
|
22 |
} |
|
23 |
\isamarkuptrue% |
|
24 |
% |
|
42096 | 25 |
\isamarkupsubsection{Specialities of the \isa{Scala} target language \label{sec:scala}% |
26 |
} |
|
27 |
\isamarkuptrue% |
|
28 |
% |
|
29 |
\begin{isamarkuptext}% |
|
30 |
\isa{Scala} deviates from languages of the ML family in a couple |
|
31 |
of aspects; those which affect code generation mainly have to do with |
|
32 |
\isa{Scala}'s type system: |
|
33 |
||
34 |
\begin{itemize} |
|
35 |
||
36 |
\item \isa{Scala} prefers tupled syntax over curried syntax. |
|
37 |
||
38 |
\item \isa{Scala} sacrifices Hindely-Milner type inference for a |
|
39 |
much more rich type system with subtyping etc. For this reason |
|
40 |
type arguments sometimes have to be given explicitly in square |
|
46523 | 41 |
brackets (mimicking System F syntax). |
42096 | 42 |
|
43 |
\item In contrast to \isa{Haskell} where most specialities of |
|
44 |
the type system are implemented using \emph{type classes}, |
|
45 |
\isa{Scala} provides a sophisticated system of \emph{implicit |
|
46 |
arguments}. |
|
47 |
||
48 |
\end{itemize} |
|
49 |
||
50 |
\noindent Concerning currying, the \isa{Scala} serializer counts |
|
51 |
arguments in code equations to determine how many arguments |
|
52 |
shall be tupled; remaining arguments and abstractions in terms |
|
53 |
rather than function definitions are always curried. |
|
54 |
||
55 |
The second aspect affects user-defined adaptations with \hyperlink{command.code-const}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}const}}}}. For regular terms, the \isa{Scala} serializer prints |
|
56 |
all type arguments explicitly. For user-defined term adaptations |
|
57 |
this is only possible for adaptations which take no arguments: here |
|
58 |
the type arguments are just appended. Otherwise they are ignored; |
|
59 |
hence user-defined adaptations for polymorphic constants have to be |
|
60 |
designed very carefully to avoid ambiguity. |
|
61 |
||
62 |
Isabelle's type classes are mapped onto \isa{Scala} implicits; in |
|
63 |
cases with diamonds in the subclass hierarchy this can lead to |
|
64 |
ambiguities in the generated code:% |
|
65 |
\end{isamarkuptext}% |
|
66 |
\isamarkuptrue% |
|
67 |
% |
|
68 |
\isadelimquote |
|
69 |
% |
|
70 |
\endisadelimquote |
|
71 |
% |
|
72 |
\isatagquote |
|
73 |
\isacommand{class}\isamarkupfalse% |
|
74 |
\ class{\isadigit{1}}\ {\isaliteral{3D}{\isacharequal}}\isanewline |
|
75 |
\ \ \isakeyword{fixes}\ foo\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{27}{\isacharprime}}a\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{27}{\isacharprime}}a{\isaliteral{22}{\isachardoublequoteclose}}\isanewline |
|
76 |
\isanewline |
|
77 |
\isacommand{class}\isamarkupfalse% |
|
78 |
\ class{\isadigit{2}}\ {\isaliteral{3D}{\isacharequal}}\ class{\isadigit{1}}\isanewline |
|
79 |
\isanewline |
|
80 |
\isacommand{class}\isamarkupfalse% |
|
81 |
\ class{\isadigit{3}}\ {\isaliteral{3D}{\isacharequal}}\ class{\isadigit{1}}% |
|
82 |
\endisatagquote |
|
83 |
{\isafoldquote}% |
|
84 |
% |
|
85 |
\isadelimquote |
|
86 |
% |
|
87 |
\endisadelimquote |
|
88 |
% |
|
89 |
\begin{isamarkuptext}% |
|
90 |
\noindent Here both \isa{class{\isadigit{2}}} and \isa{class{\isadigit{3}}} inherit from \isa{class{\isadigit{1}}}, |
|
91 |
forming the upper part of a diamond.% |
|
92 |
\end{isamarkuptext}% |
|
93 |
\isamarkuptrue% |
|
94 |
% |
|
95 |
\isadelimquote |
|
96 |
% |
|
97 |
\endisadelimquote |
|
98 |
% |
|
99 |
\isatagquote |
|
100 |
\isacommand{definition}\isamarkupfalse% |
|
101 |
\ bar\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{27}{\isacharprime}}a\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{7B}{\isacharbraceleft}}class{\isadigit{2}}{\isaliteral{2C}{\isacharcomma}}\ class{\isadigit{3}}{\isaliteral{7D}{\isacharbraceright}}\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{27}{\isacharprime}}a{\isaliteral{22}{\isachardoublequoteclose}}\ \isakeyword{where}\isanewline |
|
102 |
\ \ {\isaliteral{22}{\isachardoublequoteopen}}bar\ {\isaliteral{3D}{\isacharequal}}\ foo{\isaliteral{22}{\isachardoublequoteclose}}% |
|
103 |
\endisatagquote |
|
104 |
{\isafoldquote}% |
|
105 |
% |
|
106 |
\isadelimquote |
|
107 |
% |
|
108 |
\endisadelimquote |
|
109 |
% |
|
110 |
\begin{isamarkuptext}% |
|
111 |
\noindent This yields the following code:% |
|
112 |
\end{isamarkuptext}% |
|
113 |
\isamarkuptrue% |
|
114 |
% |
|
115 |
\isadelimquotetypewriter |
|
116 |
% |
|
117 |
\endisadelimquotetypewriter |
|
118 |
% |
|
119 |
\isatagquotetypewriter |
|
120 |
% |
|
121 |
\begin{isamarkuptext}% |
|
122 |
object\ Example\ {\isaliteral{7B}{\isacharbraceleft}}\isanewline |
|
123 |
\isanewline |
|
124 |
trait\ class{\isadigit{1}}{\isaliteral{5B}{\isacharbrackleft}}A{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{7B}{\isacharbraceleft}}\isanewline |
|
125 |
\ \ val\ {\isaliteral{60}{\isacharbackquote}}Example{\isaliteral{2E}{\isachardot}}foo{\isaliteral{60}{\isacharbackquote}}{\isaliteral{3A}{\isacharcolon}}\ A\ {\isaliteral{3D}{\isacharequal}}{\isaliteral{3E}{\isachargreater}}\ A\isanewline |
|
126 |
{\isaliteral{7D}{\isacharbraceright}}\isanewline |
|
127 |
def\ foo{\isaliteral{5B}{\isacharbrackleft}}A{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{28}{\isacharparenleft}}a{\isaliteral{3A}{\isacharcolon}}\ A{\isaliteral{29}{\isacharparenright}}{\isaliteral{28}{\isacharparenleft}}implicit\ A{\isaliteral{3A}{\isacharcolon}}\ class{\isadigit{1}}{\isaliteral{5B}{\isacharbrackleft}}A{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{3A}{\isacharcolon}}\ A\ {\isaliteral{3D}{\isacharequal}}\ A{\isaliteral{2E}{\isachardot}}{\isaliteral{60}{\isacharbackquote}}Example{\isaliteral{2E}{\isachardot}}foo{\isaliteral{60}{\isacharbackquote}}{\isaliteral{28}{\isacharparenleft}}a{\isaliteral{29}{\isacharparenright}}\isanewline |
|
128 |
\isanewline |
|
129 |
trait\ class{\isadigit{2}}{\isaliteral{5B}{\isacharbrackleft}}A{\isaliteral{5D}{\isacharbrackright}}\ extends\ class{\isadigit{1}}{\isaliteral{5B}{\isacharbrackleft}}A{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{7B}{\isacharbraceleft}}\isanewline |
|
130 |
{\isaliteral{7D}{\isacharbraceright}}\isanewline |
|
131 |
\isanewline |
|
132 |
trait\ class{\isadigit{3}}{\isaliteral{5B}{\isacharbrackleft}}A{\isaliteral{5D}{\isacharbrackright}}\ extends\ class{\isadigit{1}}{\isaliteral{5B}{\isacharbrackleft}}A{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{7B}{\isacharbraceleft}}\isanewline |
|
133 |
{\isaliteral{7D}{\isacharbraceright}}\isanewline |
|
134 |
\isanewline |
|
135 |
def\ bar{\isaliteral{5B}{\isacharbrackleft}}A\ {\isaliteral{3A}{\isacharcolon}}\ class{\isadigit{2}}\ {\isaliteral{3A}{\isacharcolon}}\ class{\isadigit{3}}{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{3A}{\isacharcolon}}\ A\ {\isaliteral{3D}{\isacharequal}}{\isaliteral{3E}{\isachargreater}}\ A\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{28}{\isacharparenleft}}a{\isaliteral{3A}{\isacharcolon}}\ A{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}{\isaliteral{3E}{\isachargreater}}\ foo{\isaliteral{5B}{\isacharbrackleft}}A{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{28}{\isacharparenleft}}a{\isaliteral{29}{\isacharparenright}}\isanewline |
|
136 |
\isanewline |
|
137 |
{\isaliteral{7D}{\isacharbraceright}}\ {\isaliteral{2F}{\isacharslash}}{\isaliteral{2A}{\isacharasterisk}}\ object\ Example\ {\isaliteral{2A}{\isacharasterisk}}{\isaliteral{2F}{\isacharslash}}\isanewline% |
|
138 |
\end{isamarkuptext}% |
|
139 |
\isamarkuptrue% |
|
140 |
% |
|
141 |
\endisatagquotetypewriter |
|
142 |
{\isafoldquotetypewriter}% |
|
143 |
% |
|
144 |
\isadelimquotetypewriter |
|
145 |
% |
|
146 |
\endisadelimquotetypewriter |
|
147 |
% |
|
148 |
\begin{isamarkuptext}% |
|
149 |
\noindent This code is rejected by the \isa{Scala} compiler: in |
|
150 |
the definition of \isa{bar}, it is not clear from where to derive |
|
151 |
the implicit argument for \isa{foo}. |
|
152 |
||
153 |
The solution to the problem is to close the diamond by a further |
|
154 |
class with inherits from both \isa{class{\isadigit{2}}} and \isa{class{\isadigit{3}}}:% |
|
155 |
\end{isamarkuptext}% |
|
156 |
\isamarkuptrue% |
|
157 |
% |
|
158 |
\isadelimquote |
|
159 |
% |
|
160 |
\endisadelimquote |
|
161 |
% |
|
162 |
\isatagquote |
|
163 |
\isacommand{class}\isamarkupfalse% |
|
164 |
\ class{\isadigit{4}}\ {\isaliteral{3D}{\isacharequal}}\ class{\isadigit{2}}\ {\isaliteral{2B}{\isacharplus}}\ class{\isadigit{3}}% |
|
165 |
\endisatagquote |
|
166 |
{\isafoldquote}% |
|
167 |
% |
|
168 |
\isadelimquote |
|
169 |
% |
|
170 |
\endisadelimquote |
|
171 |
% |
|
172 |
\begin{isamarkuptext}% |
|
173 |
\noindent Then the offending code equation can be restricted to |
|
174 |
\isa{class{\isadigit{4}}}:% |
|
175 |
\end{isamarkuptext}% |
|
176 |
\isamarkuptrue% |
|
177 |
% |
|
178 |
\isadelimquote |
|
179 |
% |
|
180 |
\endisadelimquote |
|
181 |
% |
|
182 |
\isatagquote |
|
183 |
\isacommand{lemma}\isamarkupfalse% |
|
184 |
\ {\isaliteral{5B}{\isacharbrackleft}}code{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{3A}{\isacharcolon}}\isanewline |
|
185 |
\ \ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{28}{\isacharparenleft}}bar\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{27}{\isacharprime}}a{\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}class{\isadigit{4}}\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{27}{\isacharprime}}a{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ foo{\isaliteral{22}{\isachardoublequoteclose}}\isanewline |
|
186 |
\ \ \isacommand{by}\isamarkupfalse% |
|
187 |
\ {\isaliteral{28}{\isacharparenleft}}simp\ only{\isaliteral{3A}{\isacharcolon}}\ bar{\isaliteral{5F}{\isacharunderscore}}def{\isaliteral{29}{\isacharparenright}}% |
|
188 |
\endisatagquote |
|
189 |
{\isafoldquote}% |
|
190 |
% |
|
191 |
\isadelimquote |
|
192 |
% |
|
193 |
\endisadelimquote |
|
194 |
% |
|
195 |
\begin{isamarkuptext}% |
|
196 |
\noindent with the following code:% |
|
197 |
\end{isamarkuptext}% |
|
198 |
\isamarkuptrue% |
|
199 |
% |
|
200 |
\isadelimquotetypewriter |
|
201 |
% |
|
202 |
\endisadelimquotetypewriter |
|
203 |
% |
|
204 |
\isatagquotetypewriter |
|
205 |
% |
|
206 |
\begin{isamarkuptext}% |
|
207 |
object\ Example\ {\isaliteral{7B}{\isacharbraceleft}}\isanewline |
|
208 |
\isanewline |
|
209 |
trait\ class{\isadigit{1}}{\isaliteral{5B}{\isacharbrackleft}}A{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{7B}{\isacharbraceleft}}\isanewline |
|
210 |
\ \ val\ {\isaliteral{60}{\isacharbackquote}}Example{\isaliteral{2E}{\isachardot}}foo{\isaliteral{60}{\isacharbackquote}}{\isaliteral{3A}{\isacharcolon}}\ A\ {\isaliteral{3D}{\isacharequal}}{\isaliteral{3E}{\isachargreater}}\ A\isanewline |
|
211 |
{\isaliteral{7D}{\isacharbraceright}}\isanewline |
|
212 |
def\ foo{\isaliteral{5B}{\isacharbrackleft}}A{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{28}{\isacharparenleft}}a{\isaliteral{3A}{\isacharcolon}}\ A{\isaliteral{29}{\isacharparenright}}{\isaliteral{28}{\isacharparenleft}}implicit\ A{\isaliteral{3A}{\isacharcolon}}\ class{\isadigit{1}}{\isaliteral{5B}{\isacharbrackleft}}A{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{29}{\isacharparenright}}{\isaliteral{3A}{\isacharcolon}}\ A\ {\isaliteral{3D}{\isacharequal}}\ A{\isaliteral{2E}{\isachardot}}{\isaliteral{60}{\isacharbackquote}}Example{\isaliteral{2E}{\isachardot}}foo{\isaliteral{60}{\isacharbackquote}}{\isaliteral{28}{\isacharparenleft}}a{\isaliteral{29}{\isacharparenright}}\isanewline |
|
213 |
\isanewline |
|
214 |
trait\ class{\isadigit{2}}{\isaliteral{5B}{\isacharbrackleft}}A{\isaliteral{5D}{\isacharbrackright}}\ extends\ class{\isadigit{1}}{\isaliteral{5B}{\isacharbrackleft}}A{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{7B}{\isacharbraceleft}}\isanewline |
|
215 |
{\isaliteral{7D}{\isacharbraceright}}\isanewline |
|
216 |
\isanewline |
|
217 |
trait\ class{\isadigit{3}}{\isaliteral{5B}{\isacharbrackleft}}A{\isaliteral{5D}{\isacharbrackright}}\ extends\ class{\isadigit{1}}{\isaliteral{5B}{\isacharbrackleft}}A{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{7B}{\isacharbraceleft}}\isanewline |
|
218 |
{\isaliteral{7D}{\isacharbraceright}}\isanewline |
|
219 |
\isanewline |
|
220 |
trait\ class{\isadigit{4}}{\isaliteral{5B}{\isacharbrackleft}}A{\isaliteral{5D}{\isacharbrackright}}\ extends\ class{\isadigit{2}}{\isaliteral{5B}{\isacharbrackleft}}A{\isaliteral{5D}{\isacharbrackright}}\ with\ class{\isadigit{3}}{\isaliteral{5B}{\isacharbrackleft}}A{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{7B}{\isacharbraceleft}}\isanewline |
|
221 |
{\isaliteral{7D}{\isacharbraceright}}\isanewline |
|
222 |
\isanewline |
|
223 |
def\ bar{\isaliteral{5B}{\isacharbrackleft}}A\ {\isaliteral{3A}{\isacharcolon}}\ class{\isadigit{4}}{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{3A}{\isacharcolon}}\ A\ {\isaliteral{3D}{\isacharequal}}{\isaliteral{3E}{\isachargreater}}\ A\ {\isaliteral{3D}{\isacharequal}}\ {\isaliteral{28}{\isacharparenleft}}a{\isaliteral{3A}{\isacharcolon}}\ A{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}{\isaliteral{3E}{\isachargreater}}\ foo{\isaliteral{5B}{\isacharbrackleft}}A{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{28}{\isacharparenleft}}a{\isaliteral{29}{\isacharparenright}}\isanewline |
|
224 |
\isanewline |
|
225 |
{\isaliteral{7D}{\isacharbraceright}}\ {\isaliteral{2F}{\isacharslash}}{\isaliteral{2A}{\isacharasterisk}}\ object\ Example\ {\isaliteral{2A}{\isacharasterisk}}{\isaliteral{2F}{\isacharslash}}\isanewline% |
|
226 |
\end{isamarkuptext}% |
|
227 |
\isamarkuptrue% |
|
228 |
% |
|
229 |
\endisatagquotetypewriter |
|
230 |
{\isafoldquotetypewriter}% |
|
231 |
% |
|
232 |
\isadelimquotetypewriter |
|
233 |
% |
|
234 |
\endisadelimquotetypewriter |
|
235 |
% |
|
236 |
\begin{isamarkuptext}% |
|
237 |
\noindent which exposes no ambiguity. |
|
238 |
||
239 |
Since the preprocessor (cf.~\secref{sec:preproc}) propagates sort |
|
240 |
constraints through a system of code equations, it is usually not |
|
241 |
very difficult to identify the set of code equations which actually |
|
242 |
needs more restricted sort constraints.% |
|
243 |
\end{isamarkuptext}% |
|
244 |
\isamarkuptrue% |
|
245 |
% |
|
38437 | 246 |
\isamarkupsubsection{Modules namespace% |
28447 | 247 |
} |
248 |
\isamarkuptrue% |
|
249 |
% |
|
250 |
\begin{isamarkuptext}% |
|
40755 | 251 |
When invoking the \hyperlink{command.export-code}{\mbox{\isa{\isacommand{export{\isaliteral{5F}{\isacharunderscore}}code}}}} command it is possible to |
252 |
leave out the \hyperlink{keyword.module-name}{\mbox{\isa{\isakeyword{module{\isaliteral{5F}{\isacharunderscore}}name}}}} part; then code is |
|
253 |
distributed over different modules, where the module name space |
|
254 |
roughly is induced by the Isabelle theory name space. |
|
38437 | 255 |
|
40755 | 256 |
Then sometimes the awkward situation occurs that dependencies |
257 |
between definitions introduce cyclic dependencies between modules, |
|
258 |
which in the \isa{Haskell} world leaves you to the mercy of the |
|
259 |
\isa{Haskell} implementation you are using, while for \isa{SML}/\isa{OCaml} code generation is not possible. |
|
38437 | 260 |
|
40755 | 261 |
A solution is to declare module names explicitly. Let use assume |
262 |
the three cyclically dependent modules are named \emph{A}, \emph{B} |
|
263 |
and \emph{C}. Then, by stating% |
|
38437 | 264 |
\end{isamarkuptext}% |
265 |
\isamarkuptrue% |
|
266 |
% |
|
267 |
\isadelimquote |
|
268 |
% |
|
269 |
\endisadelimquote |
|
270 |
% |
|
271 |
\isatagquote |
|
40406 | 272 |
\isacommand{code{\isaliteral{5F}{\isacharunderscore}}modulename}\isamarkupfalse% |
38437 | 273 |
\ SML\isanewline |
274 |
\ \ A\ ABC\isanewline |
|
275 |
\ \ B\ ABC\isanewline |
|
276 |
\ \ C\ ABC% |
|
277 |
\endisatagquote |
|
278 |
{\isafoldquote}% |
|
279 |
% |
|
280 |
\isadelimquote |
|
281 |
% |
|
282 |
\endisadelimquote |
|
283 |
% |
|
284 |
\begin{isamarkuptext}% |
|
40755 | 285 |
\noindent we explicitly map all those modules on \emph{ABC}, |
286 |
resulting in an ad-hoc merge of this three modules at serialisation |
|
287 |
time.% |
|
28447 | 288 |
\end{isamarkuptext}% |
289 |
\isamarkuptrue% |
|
290 |
% |
|
37426 | 291 |
\isamarkupsubsection{Locales and interpretation% |
292 |
} |
|
293 |
\isamarkuptrue% |
|
294 |
% |
|
295 |
\begin{isamarkuptext}% |
|
296 |
A technical issue comes to surface when generating code from |
|
297 |
specifications stemming from locale interpretation. |
|
298 |
||
40755 | 299 |
Let us assume a locale specifying a power operation on arbitrary |
300 |
types:% |
|
37426 | 301 |
\end{isamarkuptext}% |
302 |
\isamarkuptrue% |
|
303 |
% |
|
304 |
\isadelimquote |
|
305 |
% |
|
306 |
\endisadelimquote |
|
307 |
% |
|
308 |
\isatagquote |
|
309 |
\isacommand{locale}\isamarkupfalse% |
|
40406 | 310 |
\ power\ {\isaliteral{3D}{\isacharequal}}\isanewline |
311 |
\ \ \isakeyword{fixes}\ power\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{27}{\isacharprime}}a\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{27}{\isacharprime}}b\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{27}{\isacharprime}}b{\isaliteral{22}{\isachardoublequoteclose}}\isanewline |
|
312 |
\ \ \isakeyword{assumes}\ power{\isaliteral{5F}{\isacharunderscore}}commute{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}power\ x\ {\isaliteral{5C3C636972633E}{\isasymcirc}}\ power\ y\ {\isaliteral{3D}{\isacharequal}}\ power\ y\ {\isaliteral{5C3C636972633E}{\isasymcirc}}\ power\ x{\isaliteral{22}{\isachardoublequoteclose}}\isanewline |
|
37426 | 313 |
\isakeyword{begin}% |
314 |
\endisatagquote |
|
315 |
{\isafoldquote}% |
|
316 |
% |
|
317 |
\isadelimquote |
|
318 |
% |
|
319 |
\endisadelimquote |
|
320 |
% |
|
321 |
\begin{isamarkuptext}% |
|
40755 | 322 |
\noindent Inside that locale we can lift \isa{power} to exponent |
323 |
lists by means of specification relative to that locale:% |
|
37426 | 324 |
\end{isamarkuptext}% |
325 |
\isamarkuptrue% |
|
326 |
% |
|
327 |
\isadelimquote |
|
328 |
% |
|
329 |
\endisadelimquote |
|
330 |
% |
|
331 |
\isatagquote |
|
332 |
\isacommand{primrec}\isamarkupfalse% |
|
40406 | 333 |
\ powers\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{27}{\isacharprime}}a\ list\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{27}{\isacharprime}}b\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{27}{\isacharprime}}b{\isaliteral{22}{\isachardoublequoteclose}}\ \isakeyword{where}\isanewline |
334 |
\ \ {\isaliteral{22}{\isachardoublequoteopen}}powers\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{3D}{\isacharequal}}\ id{\isaliteral{22}{\isachardoublequoteclose}}\isanewline |
|
335 |
{\isaliteral{7C}{\isacharbar}}\ {\isaliteral{22}{\isachardoublequoteopen}}powers\ {\isaliteral{28}{\isacharparenleft}}x\ {\isaliteral{23}{\isacharhash}}\ xs{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ power\ x\ {\isaliteral{5C3C636972633E}{\isasymcirc}}\ powers\ xs{\isaliteral{22}{\isachardoublequoteclose}}\isanewline |
|
37426 | 336 |
\isanewline |
337 |
\isacommand{lemma}\isamarkupfalse% |
|
40406 | 338 |
\ powers{\isaliteral{5F}{\isacharunderscore}}append{\isaliteral{3A}{\isacharcolon}}\isanewline |
339 |
\ \ {\isaliteral{22}{\isachardoublequoteopen}}powers\ {\isaliteral{28}{\isacharparenleft}}xs\ {\isaliteral{40}{\isacharat}}\ ys{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ powers\ xs\ {\isaliteral{5C3C636972633E}{\isasymcirc}}\ powers\ ys{\isaliteral{22}{\isachardoublequoteclose}}\isanewline |
|
37426 | 340 |
\ \ \isacommand{by}\isamarkupfalse% |
40406 | 341 |
\ {\isaliteral{28}{\isacharparenleft}}induct\ xs{\isaliteral{29}{\isacharparenright}}\ simp{\isaliteral{5F}{\isacharunderscore}}all\isanewline |
37426 | 342 |
\isanewline |
343 |
\isacommand{lemma}\isamarkupfalse% |
|
40406 | 344 |
\ powers{\isaliteral{5F}{\isacharunderscore}}power{\isaliteral{3A}{\isacharcolon}}\isanewline |
345 |
\ \ {\isaliteral{22}{\isachardoublequoteopen}}powers\ xs\ {\isaliteral{5C3C636972633E}{\isasymcirc}}\ power\ x\ {\isaliteral{3D}{\isacharequal}}\ power\ x\ {\isaliteral{5C3C636972633E}{\isasymcirc}}\ powers\ xs{\isaliteral{22}{\isachardoublequoteclose}}\isanewline |
|
37426 | 346 |
\ \ \isacommand{by}\isamarkupfalse% |
40406 | 347 |
\ {\isaliteral{28}{\isacharparenleft}}induct\ xs{\isaliteral{29}{\isacharparenright}}\isanewline |
348 |
\ \ \ \ {\isaliteral{28}{\isacharparenleft}}simp{\isaliteral{5F}{\isacharunderscore}}all\ del{\isaliteral{3A}{\isacharcolon}}\ o{\isaliteral{5F}{\isacharunderscore}}apply\ id{\isaliteral{5F}{\isacharunderscore}}apply\ add{\isaliteral{3A}{\isacharcolon}}\ o{\isaliteral{5F}{\isacharunderscore}}assoc\ {\isaliteral{5B}{\isacharbrackleft}}symmetric{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{2C}{\isacharcomma}}\isanewline |
|
349 |
\ \ \ \ \ \ simp\ del{\isaliteral{3A}{\isacharcolon}}\ o{\isaliteral{5F}{\isacharunderscore}}apply\ add{\isaliteral{3A}{\isacharcolon}}\ o{\isaliteral{5F}{\isacharunderscore}}assoc\ power{\isaliteral{5F}{\isacharunderscore}}commute{\isaliteral{29}{\isacharparenright}}\isanewline |
|
37426 | 350 |
\isanewline |
351 |
\isacommand{lemma}\isamarkupfalse% |
|
40406 | 352 |
\ powers{\isaliteral{5F}{\isacharunderscore}}rev{\isaliteral{3A}{\isacharcolon}}\isanewline |
353 |
\ \ {\isaliteral{22}{\isachardoublequoteopen}}powers\ {\isaliteral{28}{\isacharparenleft}}rev\ xs{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ powers\ xs{\isaliteral{22}{\isachardoublequoteclose}}\isanewline |
|
37426 | 354 |
\ \ \ \ \isacommand{by}\isamarkupfalse% |
40406 | 355 |
\ {\isaliteral{28}{\isacharparenleft}}induct\ xs{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{28}{\isacharparenleft}}simp{\isaliteral{5F}{\isacharunderscore}}all\ add{\isaliteral{3A}{\isacharcolon}}\ powers{\isaliteral{5F}{\isacharunderscore}}append\ powers{\isaliteral{5F}{\isacharunderscore}}power{\isaliteral{29}{\isacharparenright}}\isanewline |
37426 | 356 |
\isanewline |
357 |
\isacommand{end}\isamarkupfalse% |
|
358 |
% |
|
359 |
\endisatagquote |
|
360 |
{\isafoldquote}% |
|
361 |
% |
|
362 |
\isadelimquote |
|
363 |
% |
|
364 |
\endisadelimquote |
|
365 |
% |
|
366 |
\begin{isamarkuptext}% |
|
40406 | 367 |
After an interpretation of this locale (say, \indexdef{}{command}{interpretation}\hypertarget{command.interpretation}{\hyperlink{command.interpretation}{\mbox{\isa{\isacommand{interpretation}}}}} \isa{fun{\isaliteral{5F}{\isacharunderscore}}power{\isaliteral{3A}{\isacharcolon}}} \isa{{\isaliteral{22}{\isachardoublequote}}power\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{5C3C6C616D6264613E}{\isasymlambda}}n\ {\isaliteral{28}{\isacharparenleft}}f\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{27}{\isacharprime}}a\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{27}{\isacharprime}}a{\isaliteral{29}{\isacharparenright}}{\isaliteral{2E}{\isachardot}}\ f\ {\isaliteral{5E}{\isacharcircum}}{\isaliteral{5E}{\isacharcircum}}\ n{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequote}}}), one would expect to have a constant \isa{fun{\isaliteral{5F}{\isacharunderscore}}power{\isaliteral{2E}{\isachardot}}powers\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ nat\ list\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{27}{\isacharprime}}a\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{27}{\isacharprime}}a{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{27}{\isacharprime}}a\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{27}{\isacharprime}}a} for which code |
37426 | 368 |
can be generated. But this not the case: internally, the term |
40406 | 369 |
\isa{fun{\isaliteral{5F}{\isacharunderscore}}power{\isaliteral{2E}{\isachardot}}powers} is an abbreviation for the foundational |
370 |
term \isa{{\isaliteral{22}{\isachardoublequote}}power{\isaliteral{2E}{\isachardot}}powers\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{5C3C6C616D6264613E}{\isasymlambda}}n\ {\isaliteral{28}{\isacharparenleft}}f\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{27}{\isacharprime}}a\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{27}{\isacharprime}}a{\isaliteral{29}{\isacharparenright}}{\isaliteral{2E}{\isachardot}}\ f\ {\isaliteral{5E}{\isacharcircum}}{\isaliteral{5E}{\isacharcircum}}\ n{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequote}}} |
|
37426 | 371 |
(see \cite{isabelle-locale} for the details behind). |
372 |
||
40755 | 373 |
Fortunately, with minor effort the desired behaviour can be |
374 |
achieved. First, a dedicated definition of the constant on which |
|
375 |
the local \isa{powers} after interpretation is supposed to be |
|
376 |
mapped on:% |
|
37426 | 377 |
\end{isamarkuptext}% |
378 |
\isamarkuptrue% |
|
379 |
% |
|
380 |
\isadelimquote |
|
381 |
% |
|
382 |
\endisadelimquote |
|
383 |
% |
|
384 |
\isatagquote |
|
385 |
\isacommand{definition}\isamarkupfalse% |
|
40406 | 386 |
\ funpows\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}nat\ list\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{27}{\isacharprime}}a\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{27}{\isacharprime}}a{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{27}{\isacharprime}}a\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{27}{\isacharprime}}a{\isaliteral{22}{\isachardoublequoteclose}}\ \isakeyword{where}\isanewline |
387 |
\ \ {\isaliteral{5B}{\isacharbrackleft}}code\ del{\isaliteral{5D}{\isacharbrackright}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{22}{\isachardoublequoteopen}}funpows\ {\isaliteral{3D}{\isacharequal}}\ power{\isaliteral{2E}{\isachardot}}powers\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{5C3C6C616D6264613E}{\isasymlambda}}n\ f{\isaliteral{2E}{\isachardot}}\ f\ {\isaliteral{5E}{\isacharcircum}}{\isaliteral{5E}{\isacharcircum}}\ n{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}% |
|
37426 | 388 |
\endisatagquote |
389 |
{\isafoldquote}% |
|
390 |
% |
|
391 |
\isadelimquote |
|
392 |
% |
|
393 |
\endisadelimquote |
|
394 |
% |
|
395 |
\begin{isamarkuptext}% |
|
40755 | 396 |
\noindent In general, the pattern is \isa{c\ {\isaliteral{3D}{\isacharequal}}\ t} where \isa{c} |
397 |
is the name of the future constant and \isa{t} the foundational |
|
398 |
term corresponding to the local constant after interpretation. |
|
37426 | 399 |
|
40406 | 400 |
The interpretation itself is enriched with an equation \isa{t\ {\isaliteral{3D}{\isacharequal}}\ c}:% |
37426 | 401 |
\end{isamarkuptext}% |
402 |
\isamarkuptrue% |
|
403 |
% |
|
404 |
\isadelimquote |
|
405 |
% |
|
406 |
\endisadelimquote |
|
407 |
% |
|
408 |
\isatagquote |
|
409 |
\isacommand{interpretation}\isamarkupfalse% |
|
40406 | 410 |
\ fun{\isaliteral{5F}{\isacharunderscore}}power{\isaliteral{3A}{\isacharcolon}}\ power\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{5C3C6C616D6264613E}{\isasymlambda}}n\ {\isaliteral{28}{\isacharparenleft}}f\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{27}{\isacharprime}}a\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ {\isaliteral{27}{\isacharprime}}a{\isaliteral{29}{\isacharparenright}}{\isaliteral{2E}{\isachardot}}\ f\ {\isaliteral{5E}{\isacharcircum}}{\isaliteral{5E}{\isacharcircum}}\ n{\isaliteral{22}{\isachardoublequoteclose}}\ \isakeyword{where}\isanewline |
411 |
\ \ {\isaliteral{22}{\isachardoublequoteopen}}power{\isaliteral{2E}{\isachardot}}powers\ {\isaliteral{28}{\isacharparenleft}}{\isaliteral{5C3C6C616D6264613E}{\isasymlambda}}n\ f{\isaliteral{2E}{\isachardot}}\ f\ {\isaliteral{5E}{\isacharcircum}}{\isaliteral{5E}{\isacharcircum}}\ n{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ funpows{\isaliteral{22}{\isachardoublequoteclose}}\isanewline |
|
37426 | 412 |
\ \ \isacommand{by}\isamarkupfalse% |
40406 | 413 |
\ unfold{\isaliteral{5F}{\isacharunderscore}}locales\isanewline |
414 |
\ \ \ \ {\isaliteral{28}{\isacharparenleft}}simp{\isaliteral{5F}{\isacharunderscore}}all\ add{\isaliteral{3A}{\isacharcolon}}\ fun{\isaliteral{5F}{\isacharunderscore}}eq{\isaliteral{5F}{\isacharunderscore}}iff\ funpow{\isaliteral{5F}{\isacharunderscore}}mult\ mult{\isaliteral{5F}{\isacharunderscore}}commute\ funpows{\isaliteral{5F}{\isacharunderscore}}def{\isaliteral{29}{\isacharparenright}}% |
|
37426 | 415 |
\endisatagquote |
416 |
{\isafoldquote}% |
|
417 |
% |
|
418 |
\isadelimquote |
|
419 |
% |
|
420 |
\endisadelimquote |
|
421 |
% |
|
422 |
\begin{isamarkuptext}% |
|
40755 | 423 |
\noindent This additional equation is trivially proved by the |
424 |
definition itself. |
|
37426 | 425 |
|
426 |
After this setup procedure, code generation can continue as usual:% |
|
427 |
\end{isamarkuptext}% |
|
428 |
\isamarkuptrue% |
|
429 |
% |
|
39745 | 430 |
\isadelimquotetypewriter |
37426 | 431 |
% |
39745 | 432 |
\endisadelimquotetypewriter |
37426 | 433 |
% |
39745 | 434 |
\isatagquotetypewriter |
37426 | 435 |
% |
436 |
\begin{isamarkuptext}% |
|
40406 | 437 |
funpow\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ forall\ a{\isaliteral{2E}{\isachardot}}\ Nat\ {\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ {\isaliteral{28}{\isacharparenleft}}a\ {\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ a{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ a\ {\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ a{\isaliteral{3B}{\isacharsemicolon}}\isanewline |
438 |
funpow\ Zero{\isaliteral{5F}{\isacharunderscore}}nat\ f\ {\isaliteral{3D}{\isacharequal}}\ id{\isaliteral{3B}{\isacharsemicolon}}\isanewline |
|
439 |
funpow\ {\isaliteral{28}{\isacharparenleft}}Suc\ n{\isaliteral{29}{\isacharparenright}}\ f\ {\isaliteral{3D}{\isacharequal}}\ f\ {\isaliteral{2E}{\isachardot}}\ funpow\ n\ f{\isaliteral{3B}{\isacharsemicolon}}\isanewline |
|
39664
0afaf89ab591
more canonical type setting of type writer code examples
haftmann
parents:
39559
diff
changeset
|
440 |
\isanewline |
40406 | 441 |
funpows\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ forall\ a{\isaliteral{2E}{\isachardot}}\ {\isaliteral{5B}{\isacharbrackleft}}Nat{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ {\isaliteral{28}{\isacharparenleft}}a\ {\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ a{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ a\ {\isaliteral{2D}{\isacharminus}}{\isaliteral{3E}{\isachargreater}}\ a{\isaliteral{3B}{\isacharsemicolon}}\isanewline |
442 |
funpows\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{3D}{\isacharequal}}\ id{\isaliteral{3B}{\isacharsemicolon}}\isanewline |
|
443 |
funpows\ {\isaliteral{28}{\isacharparenleft}}x\ {\isaliteral{3A}{\isacharcolon}}\ xs{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ funpow\ x\ {\isaliteral{2E}{\isachardot}}\ funpows\ xs{\isaliteral{3B}{\isacharsemicolon}}\isanewline% |
|
37426 | 444 |
\end{isamarkuptext}% |
445 |
\isamarkuptrue% |
|
446 |
% |
|
39745 | 447 |
\endisatagquotetypewriter |
448 |
{\isafoldquotetypewriter}% |
|
37426 | 449 |
% |
39745 | 450 |
\isadelimquotetypewriter |
37426 | 451 |
% |
39745 | 452 |
\endisadelimquotetypewriter |
37426 | 453 |
% |
38437 | 454 |
\isamarkupsubsection{Imperative data structures% |
28447 | 455 |
} |
456 |
\isamarkuptrue% |
|
457 |
% |
|
458 |
\begin{isamarkuptext}% |
|
38437 | 459 |
If you consider imperative data structures as inevitable for a |
460 |
specific application, you should consider \emph{Imperative |
|
461 |
Functional Programming with Isabelle/HOL} |
|
462 |
\cite{bulwahn-et-al:2008:imperative}; the framework described there |
|
40755 | 463 |
is available in session \isa{Imperative{\isaliteral{5F}{\isacharunderscore}}HOL}, together with a |
464 |
short primer document.% |
|
28447 | 465 |
\end{isamarkuptext}% |
466 |
\isamarkuptrue% |
|
467 |
% |
|
38405 | 468 |
\isamarkupsubsection{ML system interfaces \label{sec:ml}% |
469 |
} |
|
470 |
\isamarkuptrue% |
|
471 |
% |
|
472 |
\begin{isamarkuptext}% |
|
38510 | 473 |
Since the code generator framework not only aims to provide a nice |
474 |
Isar interface but also to form a base for code-generation-based |
|
475 |
applications, here a short description of the most fundamental ML |
|
476 |
interfaces.% |
|
38405 | 477 |
\end{isamarkuptext}% |
478 |
\isamarkuptrue% |
|
479 |
% |
|
480 |
\isamarkupsubsubsection{Managing executable content% |
|
481 |
} |
|
482 |
\isamarkuptrue% |
|
483 |
% |
|
484 |
\isadelimmlref |
|
485 |
% |
|
486 |
\endisadelimmlref |
|
487 |
% |
|
488 |
\isatagmlref |
|
489 |
% |
|
490 |
\begin{isamarkuptext}% |
|
491 |
\begin{mldecls} |
|
38510 | 492 |
\indexdef{}{ML}{Code.read\_const}\verb|Code.read_const: theory -> string -> string| \\ |
38405 | 493 |
\indexdef{}{ML}{Code.add\_eqn}\verb|Code.add_eqn: thm -> theory -> theory| \\ |
494 |
\indexdef{}{ML}{Code.del\_eqn}\verb|Code.del_eqn: thm -> theory -> theory| \\ |
|
495 |
\indexdef{}{ML}{Code\_Preproc.map\_pre}\verb|Code_Preproc.map_pre: (simpset -> simpset) -> theory -> theory| \\ |
|
496 |
\indexdef{}{ML}{Code\_Preproc.map\_post}\verb|Code_Preproc.map_post: (simpset -> simpset) -> theory -> theory| \\ |
|
38509 | 497 |
\indexdef{}{ML}{Code\_Preproc.add\_functrans}\verb|Code_Preproc.add_functrans: |\isasep\isanewline% |
498 |
\verb| string * (theory -> (thm * bool) list -> (thm * bool) list option)|\isasep\isanewline% |
|
499 |
\verb| -> theory -> theory| \\ |
|
38405 | 500 |
\indexdef{}{ML}{Code\_Preproc.del\_functrans}\verb|Code_Preproc.del_functrans: string -> theory -> theory| \\ |
501 |
\indexdef{}{ML}{Code.add\_datatype}\verb|Code.add_datatype: (string * typ) list -> theory -> theory| \\ |
|
502 |
\indexdef{}{ML}{Code.get\_type}\verb|Code.get_type: theory -> string|\isasep\isanewline% |
|
40755 | 503 |
\verb| -> ((string * sort) list * (string * ((string * sort) list * typ list)) list) * bool| \\ |
38405 | 504 |
\indexdef{}{ML}{Code.get\_type\_of\_constr\_or\_abstr}\verb|Code.get_type_of_constr_or_abstr: theory -> string -> (string * bool) option| |
505 |
\end{mldecls} |
|
506 |
||
507 |
\begin{description} |
|
508 |
||
38510 | 509 |
\item \verb|Code.read_const|~\isa{thy}~\isa{s} |
510 |
reads a constant as a concrete term expression \isa{s}. |
|
511 |
||
38405 | 512 |
\item \verb|Code.add_eqn|~\isa{thm}~\isa{thy} adds function |
513 |
theorem \isa{thm} to executable content. |
|
514 |
||
515 |
\item \verb|Code.del_eqn|~\isa{thm}~\isa{thy} removes function |
|
516 |
theorem \isa{thm} from executable content, if present. |
|
517 |
||
518 |
\item \verb|Code_Preproc.map_pre|~\isa{f}~\isa{thy} changes |
|
519 |
the preprocessor simpset. |
|
520 |
||
40406 | 521 |
\item \verb|Code_Preproc.add_functrans|~\isa{{\isaliteral{28}{\isacharparenleft}}name{\isaliteral{2C}{\isacharcomma}}\ f{\isaliteral{29}{\isacharparenright}}}~\isa{thy} adds |
38405 | 522 |
function transformer \isa{f} (named \isa{name}) to executable content; |
523 |
\isa{f} is a transformer of the code equations belonging |
|
524 |
to a certain function definition, depending on the |
|
525 |
current theory context. Returning \isa{NONE} indicates that no |
|
526 |
transformation took place; otherwise, the whole process will be iterated |
|
527 |
with the new code equations. |
|
528 |
||
529 |
\item \verb|Code_Preproc.del_functrans|~\isa{name}~\isa{thy} removes |
|
530 |
function transformer named \isa{name} from executable content. |
|
531 |
||
532 |
\item \verb|Code.add_datatype|~\isa{cs}~\isa{thy} adds |
|
533 |
a datatype to executable content, with generation |
|
534 |
set \isa{cs}. |
|
535 |
||
536 |
\item \verb|Code.get_type_of_constr_or_abstr|~\isa{thy}~\isa{const} |
|
537 |
returns type constructor corresponding to |
|
538 |
constructor \isa{const}; returns \isa{NONE} |
|
539 |
if \isa{const} is no constructor. |
|
540 |
||
541 |
\end{description}% |
|
542 |
\end{isamarkuptext}% |
|
543 |
\isamarkuptrue% |
|
544 |
% |
|
545 |
\endisatagmlref |
|
546 |
{\isafoldmlref}% |
|
547 |
% |
|
548 |
\isadelimmlref |
|
549 |
% |
|
550 |
\endisadelimmlref |
|
551 |
% |
|
552 |
\isamarkupsubsubsection{Data depending on the theory's executable content% |
|
553 |
} |
|
554 |
\isamarkuptrue% |
|
555 |
% |
|
556 |
\begin{isamarkuptext}% |
|
40755 | 557 |
Implementing code generator applications on top of the framework set |
558 |
out so far usually not only involves using those primitive |
|
559 |
interfaces but also storing code-dependent data and various other |
|
560 |
things. |
|
38405 | 561 |
|
40755 | 562 |
Due to incrementality of code generation, changes in the theory's |
563 |
executable content have to be propagated in a certain fashion. |
|
564 |
Additionally, such changes may occur not only during theory |
|
565 |
extension but also during theory merge, which is a little bit nasty |
|
566 |
from an implementation point of view. The framework provides a |
|
567 |
solution to this technical challenge by providing a functorial data |
|
568 |
slot \verb|Code_Data|; on instantiation of this functor, the |
|
569 |
following types and operations are required: |
|
38405 | 570 |
|
571 |
\medskip |
|
572 |
\begin{tabular}{l} |
|
573 |
\isa{type\ T} \\ |
|
40406 | 574 |
\isa{val\ empty{\isaliteral{3A}{\isacharcolon}}\ T} \\ |
38405 | 575 |
\end{tabular} |
576 |
||
577 |
\begin{description} |
|
578 |
||
579 |
\item \isa{T} the type of data to store. |
|
580 |
||
581 |
\item \isa{empty} initial (empty) data. |
|
582 |
||
583 |
\end{description} |
|
584 |
||
40755 | 585 |
\noindent An instance of \verb|Code_Data| provides the |
586 |
following interface: |
|
38405 | 587 |
|
588 |
\medskip |
|
589 |
\begin{tabular}{l} |
|
40406 | 590 |
\isa{change{\isaliteral{3A}{\isacharcolon}}\ theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ {\isaliteral{28}{\isacharparenleft}}T\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ T{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ T} \\ |
591 |
\isa{change{\isaliteral{5F}{\isacharunderscore}}yield{\isaliteral{3A}{\isacharcolon}}\ theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ {\isaliteral{28}{\isacharparenleft}}T\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ {\isaliteral{27}{\isacharprime}}a\ {\isaliteral{2A}{\isacharasterisk}}\ T{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ {\isaliteral{27}{\isacharprime}}a\ {\isaliteral{2A}{\isacharasterisk}}\ T} |
|
38405 | 592 |
\end{tabular} |
593 |
||
594 |
\begin{description} |
|
595 |
||
40755 | 596 |
\item \isa{change} update of current data (cached!) by giving a |
597 |
continuation. |
|
38405 | 598 |
|
40406 | 599 |
\item \isa{change{\isaliteral{5F}{\isacharunderscore}}yield} update with side result. |
38405 | 600 |
|
601 |
\end{description}% |
|
602 |
\end{isamarkuptext}% |
|
603 |
\isamarkuptrue% |
|
604 |
% |
|
28447 | 605 |
\isadelimtheory |
606 |
% |
|
607 |
\endisadelimtheory |
|
608 |
% |
|
609 |
\isatagtheory |
|
610 |
\isacommand{end}\isamarkupfalse% |
|
611 |
% |
|
612 |
\endisatagtheory |
|
613 |
{\isafoldtheory}% |
|
614 |
% |
|
615 |
\isadelimtheory |
|
616 |
% |
|
617 |
\endisadelimtheory |
|
618 |
\isanewline |
|
46523 | 619 |
\isanewline |
28447 | 620 |
\end{isabellebody}% |
621 |
%%% Local Variables: |
|
622 |
%%% mode: latex |
|
623 |
%%% TeX-master: "root" |
|
624 |
%%% End: |