author | bulwahn |
Wed, 23 Mar 2011 08:50:42 +0100 | |
changeset 42092 | f07b373f25d3 |
parent 40755 | d73659e8ccdd |
child 42096 | 9f6652122963 |
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 |
% |
|
38437 | 25 |
\isamarkupsubsection{Modules namespace% |
28447 | 26 |
} |
27 |
\isamarkuptrue% |
|
28 |
% |
|
29 |
\begin{isamarkuptext}% |
|
40755 | 30 |
When invoking the \hyperlink{command.export-code}{\mbox{\isa{\isacommand{export{\isaliteral{5F}{\isacharunderscore}}code}}}} command it is possible to |
31 |
leave out the \hyperlink{keyword.module-name}{\mbox{\isa{\isakeyword{module{\isaliteral{5F}{\isacharunderscore}}name}}}} part; then code is |
|
32 |
distributed over different modules, where the module name space |
|
33 |
roughly is induced by the Isabelle theory name space. |
|
38437 | 34 |
|
40755 | 35 |
Then sometimes the awkward situation occurs that dependencies |
36 |
between definitions introduce cyclic dependencies between modules, |
|
37 |
which in the \isa{Haskell} world leaves you to the mercy of the |
|
38 |
\isa{Haskell} implementation you are using, while for \isa{SML}/\isa{OCaml} code generation is not possible. |
|
38437 | 39 |
|
40755 | 40 |
A solution is to declare module names explicitly. Let use assume |
41 |
the three cyclically dependent modules are named \emph{A}, \emph{B} |
|
42 |
and \emph{C}. Then, by stating% |
|
38437 | 43 |
\end{isamarkuptext}% |
44 |
\isamarkuptrue% |
|
45 |
% |
|
46 |
\isadelimquote |
|
47 |
% |
|
48 |
\endisadelimquote |
|
49 |
% |
|
50 |
\isatagquote |
|
40406 | 51 |
\isacommand{code{\isaliteral{5F}{\isacharunderscore}}modulename}\isamarkupfalse% |
38437 | 52 |
\ SML\isanewline |
53 |
\ \ A\ ABC\isanewline |
|
54 |
\ \ B\ ABC\isanewline |
|
55 |
\ \ C\ ABC% |
|
56 |
\endisatagquote |
|
57 |
{\isafoldquote}% |
|
58 |
% |
|
59 |
\isadelimquote |
|
60 |
% |
|
61 |
\endisadelimquote |
|
62 |
% |
|
63 |
\begin{isamarkuptext}% |
|
40755 | 64 |
\noindent we explicitly map all those modules on \emph{ABC}, |
65 |
resulting in an ad-hoc merge of this three modules at serialisation |
|
66 |
time.% |
|
28447 | 67 |
\end{isamarkuptext}% |
68 |
\isamarkuptrue% |
|
69 |
% |
|
37426 | 70 |
\isamarkupsubsection{Locales and interpretation% |
71 |
} |
|
72 |
\isamarkuptrue% |
|
73 |
% |
|
74 |
\begin{isamarkuptext}% |
|
75 |
A technical issue comes to surface when generating code from |
|
76 |
specifications stemming from locale interpretation. |
|
77 |
||
40755 | 78 |
Let us assume a locale specifying a power operation on arbitrary |
79 |
types:% |
|
37426 | 80 |
\end{isamarkuptext}% |
81 |
\isamarkuptrue% |
|
82 |
% |
|
83 |
\isadelimquote |
|
84 |
% |
|
85 |
\endisadelimquote |
|
86 |
% |
|
87 |
\isatagquote |
|
88 |
\isacommand{locale}\isamarkupfalse% |
|
40406 | 89 |
\ power\ {\isaliteral{3D}{\isacharequal}}\isanewline |
90 |
\ \ \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 |
|
91 |
\ \ \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 | 92 |
\isakeyword{begin}% |
93 |
\endisatagquote |
|
94 |
{\isafoldquote}% |
|
95 |
% |
|
96 |
\isadelimquote |
|
97 |
% |
|
98 |
\endisadelimquote |
|
99 |
% |
|
100 |
\begin{isamarkuptext}% |
|
40755 | 101 |
\noindent Inside that locale we can lift \isa{power} to exponent |
102 |
lists by means of specification relative to that locale:% |
|
37426 | 103 |
\end{isamarkuptext}% |
104 |
\isamarkuptrue% |
|
105 |
% |
|
106 |
\isadelimquote |
|
107 |
% |
|
108 |
\endisadelimquote |
|
109 |
% |
|
110 |
\isatagquote |
|
111 |
\isacommand{primrec}\isamarkupfalse% |
|
40406 | 112 |
\ 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 |
113 |
\ \ {\isaliteral{22}{\isachardoublequoteopen}}powers\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{3D}{\isacharequal}}\ id{\isaliteral{22}{\isachardoublequoteclose}}\isanewline |
|
114 |
{\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 | 115 |
\isanewline |
116 |
\isacommand{lemma}\isamarkupfalse% |
|
40406 | 117 |
\ powers{\isaliteral{5F}{\isacharunderscore}}append{\isaliteral{3A}{\isacharcolon}}\isanewline |
118 |
\ \ {\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 | 119 |
\ \ \isacommand{by}\isamarkupfalse% |
40406 | 120 |
\ {\isaliteral{28}{\isacharparenleft}}induct\ xs{\isaliteral{29}{\isacharparenright}}\ simp{\isaliteral{5F}{\isacharunderscore}}all\isanewline |
37426 | 121 |
\isanewline |
122 |
\isacommand{lemma}\isamarkupfalse% |
|
40406 | 123 |
\ powers{\isaliteral{5F}{\isacharunderscore}}power{\isaliteral{3A}{\isacharcolon}}\isanewline |
124 |
\ \ {\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 | 125 |
\ \ \isacommand{by}\isamarkupfalse% |
40406 | 126 |
\ {\isaliteral{28}{\isacharparenleft}}induct\ xs{\isaliteral{29}{\isacharparenright}}\isanewline |
127 |
\ \ \ \ {\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 |
|
128 |
\ \ \ \ \ \ 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 | 129 |
\isanewline |
130 |
\isacommand{lemma}\isamarkupfalse% |
|
40406 | 131 |
\ powers{\isaliteral{5F}{\isacharunderscore}}rev{\isaliteral{3A}{\isacharcolon}}\isanewline |
132 |
\ \ {\isaliteral{22}{\isachardoublequoteopen}}powers\ {\isaliteral{28}{\isacharparenleft}}rev\ xs{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\ powers\ xs{\isaliteral{22}{\isachardoublequoteclose}}\isanewline |
|
37426 | 133 |
\ \ \ \ \isacommand{by}\isamarkupfalse% |
40406 | 134 |
\ {\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 | 135 |
\isanewline |
136 |
\isacommand{end}\isamarkupfalse% |
|
137 |
% |
|
138 |
\endisatagquote |
|
139 |
{\isafoldquote}% |
|
140 |
% |
|
141 |
\isadelimquote |
|
142 |
% |
|
143 |
\endisadelimquote |
|
144 |
% |
|
145 |
\begin{isamarkuptext}% |
|
40406 | 146 |
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 | 147 |
can be generated. But this not the case: internally, the term |
40406 | 148 |
\isa{fun{\isaliteral{5F}{\isacharunderscore}}power{\isaliteral{2E}{\isachardot}}powers} is an abbreviation for the foundational |
149 |
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 | 150 |
(see \cite{isabelle-locale} for the details behind). |
151 |
||
40755 | 152 |
Fortunately, with minor effort the desired behaviour can be |
153 |
achieved. First, a dedicated definition of the constant on which |
|
154 |
the local \isa{powers} after interpretation is supposed to be |
|
155 |
mapped on:% |
|
37426 | 156 |
\end{isamarkuptext}% |
157 |
\isamarkuptrue% |
|
158 |
% |
|
159 |
\isadelimquote |
|
160 |
% |
|
161 |
\endisadelimquote |
|
162 |
% |
|
163 |
\isatagquote |
|
164 |
\isacommand{definition}\isamarkupfalse% |
|
40406 | 165 |
\ 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 |
166 |
\ \ {\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 | 167 |
\endisatagquote |
168 |
{\isafoldquote}% |
|
169 |
% |
|
170 |
\isadelimquote |
|
171 |
% |
|
172 |
\endisadelimquote |
|
173 |
% |
|
174 |
\begin{isamarkuptext}% |
|
40755 | 175 |
\noindent In general, the pattern is \isa{c\ {\isaliteral{3D}{\isacharequal}}\ t} where \isa{c} |
176 |
is the name of the future constant and \isa{t} the foundational |
|
177 |
term corresponding to the local constant after interpretation. |
|
37426 | 178 |
|
40406 | 179 |
The interpretation itself is enriched with an equation \isa{t\ {\isaliteral{3D}{\isacharequal}}\ c}:% |
37426 | 180 |
\end{isamarkuptext}% |
181 |
\isamarkuptrue% |
|
182 |
% |
|
183 |
\isadelimquote |
|
184 |
% |
|
185 |
\endisadelimquote |
|
186 |
% |
|
187 |
\isatagquote |
|
188 |
\isacommand{interpretation}\isamarkupfalse% |
|
40406 | 189 |
\ 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 |
190 |
\ \ {\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 | 191 |
\ \ \isacommand{by}\isamarkupfalse% |
40406 | 192 |
\ unfold{\isaliteral{5F}{\isacharunderscore}}locales\isanewline |
193 |
\ \ \ \ {\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 | 194 |
\endisatagquote |
195 |
{\isafoldquote}% |
|
196 |
% |
|
197 |
\isadelimquote |
|
198 |
% |
|
199 |
\endisadelimquote |
|
200 |
% |
|
201 |
\begin{isamarkuptext}% |
|
40755 | 202 |
\noindent This additional equation is trivially proved by the |
203 |
definition itself. |
|
37426 | 204 |
|
205 |
After this setup procedure, code generation can continue as usual:% |
|
206 |
\end{isamarkuptext}% |
|
207 |
\isamarkuptrue% |
|
208 |
% |
|
39745 | 209 |
\isadelimquotetypewriter |
37426 | 210 |
% |
39745 | 211 |
\endisadelimquotetypewriter |
37426 | 212 |
% |
39745 | 213 |
\isatagquotetypewriter |
37426 | 214 |
% |
215 |
\begin{isamarkuptext}% |
|
40406 | 216 |
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 |
217 |
funpow\ Zero{\isaliteral{5F}{\isacharunderscore}}nat\ f\ {\isaliteral{3D}{\isacharequal}}\ id{\isaliteral{3B}{\isacharsemicolon}}\isanewline |
|
218 |
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
|
219 |
\isanewline |
40406 | 220 |
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 |
221 |
funpows\ {\isaliteral{5B}{\isacharbrackleft}}{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{3D}{\isacharequal}}\ id{\isaliteral{3B}{\isacharsemicolon}}\isanewline |
|
222 |
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 | 223 |
\end{isamarkuptext}% |
224 |
\isamarkuptrue% |
|
225 |
% |
|
39745 | 226 |
\endisatagquotetypewriter |
227 |
{\isafoldquotetypewriter}% |
|
37426 | 228 |
% |
39745 | 229 |
\isadelimquotetypewriter |
37426 | 230 |
% |
39745 | 231 |
\endisadelimquotetypewriter |
37426 | 232 |
% |
38437 | 233 |
\isamarkupsubsection{Imperative data structures% |
28447 | 234 |
} |
235 |
\isamarkuptrue% |
|
236 |
% |
|
237 |
\begin{isamarkuptext}% |
|
38437 | 238 |
If you consider imperative data structures as inevitable for a |
239 |
specific application, you should consider \emph{Imperative |
|
240 |
Functional Programming with Isabelle/HOL} |
|
241 |
\cite{bulwahn-et-al:2008:imperative}; the framework described there |
|
40755 | 242 |
is available in session \isa{Imperative{\isaliteral{5F}{\isacharunderscore}}HOL}, together with a |
243 |
short primer document.% |
|
28447 | 244 |
\end{isamarkuptext}% |
245 |
\isamarkuptrue% |
|
246 |
% |
|
38405 | 247 |
\isamarkupsubsection{ML system interfaces \label{sec:ml}% |
248 |
} |
|
249 |
\isamarkuptrue% |
|
250 |
% |
|
251 |
\begin{isamarkuptext}% |
|
38510 | 252 |
Since the code generator framework not only aims to provide a nice |
253 |
Isar interface but also to form a base for code-generation-based |
|
254 |
applications, here a short description of the most fundamental ML |
|
255 |
interfaces.% |
|
38405 | 256 |
\end{isamarkuptext}% |
257 |
\isamarkuptrue% |
|
258 |
% |
|
259 |
\isamarkupsubsubsection{Managing executable content% |
|
260 |
} |
|
261 |
\isamarkuptrue% |
|
262 |
% |
|
263 |
\isadelimmlref |
|
264 |
% |
|
265 |
\endisadelimmlref |
|
266 |
% |
|
267 |
\isatagmlref |
|
268 |
% |
|
269 |
\begin{isamarkuptext}% |
|
270 |
\begin{mldecls} |
|
38510 | 271 |
\indexdef{}{ML}{Code.read\_const}\verb|Code.read_const: theory -> string -> string| \\ |
38405 | 272 |
\indexdef{}{ML}{Code.add\_eqn}\verb|Code.add_eqn: thm -> theory -> theory| \\ |
273 |
\indexdef{}{ML}{Code.del\_eqn}\verb|Code.del_eqn: thm -> theory -> theory| \\ |
|
274 |
\indexdef{}{ML}{Code\_Preproc.map\_pre}\verb|Code_Preproc.map_pre: (simpset -> simpset) -> theory -> theory| \\ |
|
275 |
\indexdef{}{ML}{Code\_Preproc.map\_post}\verb|Code_Preproc.map_post: (simpset -> simpset) -> theory -> theory| \\ |
|
38509 | 276 |
\indexdef{}{ML}{Code\_Preproc.add\_functrans}\verb|Code_Preproc.add_functrans: |\isasep\isanewline% |
277 |
\verb| string * (theory -> (thm * bool) list -> (thm * bool) list option)|\isasep\isanewline% |
|
278 |
\verb| -> theory -> theory| \\ |
|
38405 | 279 |
\indexdef{}{ML}{Code\_Preproc.del\_functrans}\verb|Code_Preproc.del_functrans: string -> theory -> theory| \\ |
280 |
\indexdef{}{ML}{Code.add\_datatype}\verb|Code.add_datatype: (string * typ) list -> theory -> theory| \\ |
|
281 |
\indexdef{}{ML}{Code.get\_type}\verb|Code.get_type: theory -> string|\isasep\isanewline% |
|
40755 | 282 |
\verb| -> ((string * sort) list * (string * ((string * sort) list * typ list)) list) * bool| \\ |
38405 | 283 |
\indexdef{}{ML}{Code.get\_type\_of\_constr\_or\_abstr}\verb|Code.get_type_of_constr_or_abstr: theory -> string -> (string * bool) option| |
284 |
\end{mldecls} |
|
285 |
||
286 |
\begin{description} |
|
287 |
||
38510 | 288 |
\item \verb|Code.read_const|~\isa{thy}~\isa{s} |
289 |
reads a constant as a concrete term expression \isa{s}. |
|
290 |
||
38405 | 291 |
\item \verb|Code.add_eqn|~\isa{thm}~\isa{thy} adds function |
292 |
theorem \isa{thm} to executable content. |
|
293 |
||
294 |
\item \verb|Code.del_eqn|~\isa{thm}~\isa{thy} removes function |
|
295 |
theorem \isa{thm} from executable content, if present. |
|
296 |
||
297 |
\item \verb|Code_Preproc.map_pre|~\isa{f}~\isa{thy} changes |
|
298 |
the preprocessor simpset. |
|
299 |
||
40406 | 300 |
\item \verb|Code_Preproc.add_functrans|~\isa{{\isaliteral{28}{\isacharparenleft}}name{\isaliteral{2C}{\isacharcomma}}\ f{\isaliteral{29}{\isacharparenright}}}~\isa{thy} adds |
38405 | 301 |
function transformer \isa{f} (named \isa{name}) to executable content; |
302 |
\isa{f} is a transformer of the code equations belonging |
|
303 |
to a certain function definition, depending on the |
|
304 |
current theory context. Returning \isa{NONE} indicates that no |
|
305 |
transformation took place; otherwise, the whole process will be iterated |
|
306 |
with the new code equations. |
|
307 |
||
308 |
\item \verb|Code_Preproc.del_functrans|~\isa{name}~\isa{thy} removes |
|
309 |
function transformer named \isa{name} from executable content. |
|
310 |
||
311 |
\item \verb|Code.add_datatype|~\isa{cs}~\isa{thy} adds |
|
312 |
a datatype to executable content, with generation |
|
313 |
set \isa{cs}. |
|
314 |
||
315 |
\item \verb|Code.get_type_of_constr_or_abstr|~\isa{thy}~\isa{const} |
|
316 |
returns type constructor corresponding to |
|
317 |
constructor \isa{const}; returns \isa{NONE} |
|
318 |
if \isa{const} is no constructor. |
|
319 |
||
320 |
\end{description}% |
|
321 |
\end{isamarkuptext}% |
|
322 |
\isamarkuptrue% |
|
323 |
% |
|
324 |
\endisatagmlref |
|
325 |
{\isafoldmlref}% |
|
326 |
% |
|
327 |
\isadelimmlref |
|
328 |
% |
|
329 |
\endisadelimmlref |
|
330 |
% |
|
331 |
\isamarkupsubsubsection{Data depending on the theory's executable content% |
|
332 |
} |
|
333 |
\isamarkuptrue% |
|
334 |
% |
|
335 |
\begin{isamarkuptext}% |
|
40755 | 336 |
Implementing code generator applications on top of the framework set |
337 |
out so far usually not only involves using those primitive |
|
338 |
interfaces but also storing code-dependent data and various other |
|
339 |
things. |
|
38405 | 340 |
|
40755 | 341 |
Due to incrementality of code generation, changes in the theory's |
342 |
executable content have to be propagated in a certain fashion. |
|
343 |
Additionally, such changes may occur not only during theory |
|
344 |
extension but also during theory merge, which is a little bit nasty |
|
345 |
from an implementation point of view. The framework provides a |
|
346 |
solution to this technical challenge by providing a functorial data |
|
347 |
slot \verb|Code_Data|; on instantiation of this functor, the |
|
348 |
following types and operations are required: |
|
38405 | 349 |
|
350 |
\medskip |
|
351 |
\begin{tabular}{l} |
|
352 |
\isa{type\ T} \\ |
|
40406 | 353 |
\isa{val\ empty{\isaliteral{3A}{\isacharcolon}}\ T} \\ |
38405 | 354 |
\end{tabular} |
355 |
||
356 |
\begin{description} |
|
357 |
||
358 |
\item \isa{T} the type of data to store. |
|
359 |
||
360 |
\item \isa{empty} initial (empty) data. |
|
361 |
||
362 |
\end{description} |
|
363 |
||
40755 | 364 |
\noindent An instance of \verb|Code_Data| provides the |
365 |
following interface: |
|
38405 | 366 |
|
367 |
\medskip |
|
368 |
\begin{tabular}{l} |
|
40406 | 369 |
\isa{change{\isaliteral{3A}{\isacharcolon}}\ theory\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ {\isaliteral{28}{\isacharparenleft}}T\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ T{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{5C3C72696768746172726F773E}{\isasymrightarrow}}\ T} \\ |
370 |
\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 | 371 |
\end{tabular} |
372 |
||
373 |
\begin{description} |
|
374 |
||
40755 | 375 |
\item \isa{change} update of current data (cached!) by giving a |
376 |
continuation. |
|
38405 | 377 |
|
40406 | 378 |
\item \isa{change{\isaliteral{5F}{\isacharunderscore}}yield} update with side result. |
38405 | 379 |
|
380 |
\end{description}% |
|
381 |
\end{isamarkuptext}% |
|
382 |
\isamarkuptrue% |
|
383 |
% |
|
28447 | 384 |
\isadelimtheory |
385 |
% |
|
386 |
\endisadelimtheory |
|
387 |
% |
|
388 |
\isatagtheory |
|
389 |
\isacommand{end}\isamarkupfalse% |
|
390 |
% |
|
391 |
\endisatagtheory |
|
392 |
{\isafoldtheory}% |
|
393 |
% |
|
394 |
\isadelimtheory |
|
395 |
% |
|
396 |
\endisadelimtheory |
|
397 |
\isanewline |
|
398 |
\end{isabellebody}% |
|
399 |
%%% Local Variables: |
|
400 |
%%% mode: latex |
|
401 |
%%% TeX-master: "root" |
|
402 |
%%% End: |