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