haftmann@28447
|
1 |
%
|
haftmann@28447
|
2 |
\begin{isabellebody}%
|
haftmann@28447
|
3 |
\def\isabellecontext{Introduction}%
|
haftmann@28447
|
4 |
%
|
haftmann@28447
|
5 |
\isadelimtheory
|
haftmann@28447
|
6 |
%
|
haftmann@28447
|
7 |
\endisadelimtheory
|
haftmann@28447
|
8 |
%
|
haftmann@28447
|
9 |
\isatagtheory
|
haftmann@28447
|
10 |
\isacommand{theory}\isamarkupfalse%
|
haftmann@28447
|
11 |
\ Introduction\isanewline
|
haftmann@28447
|
12 |
\isakeyword{imports}\ Setup\isanewline
|
haftmann@28447
|
13 |
\isakeyword{begin}%
|
haftmann@28447
|
14 |
\endisatagtheory
|
haftmann@28447
|
15 |
{\isafoldtheory}%
|
haftmann@28447
|
16 |
%
|
haftmann@28447
|
17 |
\isadelimtheory
|
haftmann@28447
|
18 |
%
|
haftmann@28447
|
19 |
\endisadelimtheory
|
haftmann@28447
|
20 |
%
|
haftmann@38631
|
21 |
\isamarkupsection{Introduction%
|
haftmann@38631
|
22 |
}
|
haftmann@38631
|
23 |
\isamarkuptrue%
|
haftmann@38631
|
24 |
%
|
haftmann@38670
|
25 |
\begin{isamarkuptext}%
|
haftmann@38670
|
26 |
This tutorial introduces the code generator facilities of \isa{Isabelle{\isacharslash}HOL}. It allows to turn (a certain class of) HOL
|
haftmann@38670
|
27 |
specifications into corresponding executable code in the programming
|
haftmann@38670
|
28 |
languages \isa{SML} \cite{SML}, \isa{OCaml} \cite{OCaml} and
|
haftmann@38670
|
29 |
\isa{Haskell} \cite{haskell-revised-report}.
|
haftmann@38670
|
30 |
|
haftmann@38670
|
31 |
To profit from this tutorial, some familiarity and experience with
|
haftmann@38670
|
32 |
\hyperlink{theory.HOL}{\mbox{\isa{HOL}}} \cite{isa-tutorial} and its basic theories is assumed.%
|
haftmann@38670
|
33 |
\end{isamarkuptext}%
|
haftmann@38631
|
34 |
\isamarkuptrue%
|
haftmann@38631
|
35 |
%
|
haftmann@38670
|
36 |
\isamarkupsubsection{Code generation principle: shallow embedding \label{sec:principle}%
|
haftmann@28447
|
37 |
}
|
haftmann@28447
|
38 |
\isamarkuptrue%
|
haftmann@28447
|
39 |
%
|
haftmann@28447
|
40 |
\begin{isamarkuptext}%
|
haftmann@38670
|
41 |
The key concept for understanding Isabelle's code generation is
|
haftmann@38670
|
42 |
\emph{shallow embedding}: logical entities like constants, types and
|
haftmann@38670
|
43 |
classes are identified with corresponding entities in the target
|
haftmann@38670
|
44 |
language. In particular, the carrier of a generated program's
|
haftmann@38670
|
45 |
semantics are \emph{equational theorems} from the logic. If we view
|
haftmann@38670
|
46 |
a generated program as an implementation of a higher-order rewrite
|
haftmann@38670
|
47 |
system, then every rewrite step performed by the program can be
|
haftmann@38670
|
48 |
simulated in the logic, which guarantees partial correctness
|
haftmann@38670
|
49 |
\cite{Haftmann-Nipkow:2010:code}.%
|
haftmann@28447
|
50 |
\end{isamarkuptext}%
|
haftmann@28447
|
51 |
\isamarkuptrue%
|
haftmann@28447
|
52 |
%
|
haftmann@38670
|
53 |
\isamarkupsubsection{A quick start with the Isabelle/HOL toolbox \label{sec:queue_example}%
|
haftmann@28447
|
54 |
}
|
haftmann@28447
|
55 |
\isamarkuptrue%
|
haftmann@28447
|
56 |
%
|
haftmann@28447
|
57 |
\begin{isamarkuptext}%
|
haftmann@38670
|
58 |
In a HOL theory, the \hyperlink{command.datatype}{\mbox{\isa{\isacommand{datatype}}}} and \hyperlink{command.definition}{\mbox{\isa{\isacommand{definition}}}}/\hyperlink{command.primrec}{\mbox{\isa{\isacommand{primrec}}}}/\hyperlink{command.fun}{\mbox{\isa{\isacommand{fun}}}} declarations form the
|
haftmann@38670
|
59 |
core of a functional programming language. By default equational
|
haftmann@38670
|
60 |
theorems stemming from those are used for generated code, therefore
|
haftmann@38670
|
61 |
\qt{naive} code generation can proceed without further ado.
|
haftmann@28447
|
62 |
|
haftmann@28447
|
63 |
For example, here a simple \qt{implementation} of amortised queues:%
|
haftmann@28447
|
64 |
\end{isamarkuptext}%
|
haftmann@28447
|
65 |
\isamarkuptrue%
|
haftmann@28447
|
66 |
%
|
haftmann@28564
|
67 |
\isadelimquote
|
haftmann@28447
|
68 |
%
|
haftmann@28564
|
69 |
\endisadelimquote
|
haftmann@28447
|
70 |
%
|
haftmann@28564
|
71 |
\isatagquote
|
haftmann@28447
|
72 |
\isacommand{datatype}\isamarkupfalse%
|
haftmann@29735
|
73 |
\ {\isacharprime}a\ queue\ {\isacharequal}\ AQueue\ {\isachardoublequoteopen}{\isacharprime}a\ list{\isachardoublequoteclose}\ {\isachardoublequoteopen}{\isacharprime}a\ list{\isachardoublequoteclose}\isanewline
|
haftmann@28447
|
74 |
\isanewline
|
haftmann@28447
|
75 |
\isacommand{definition}\isamarkupfalse%
|
haftmann@28447
|
76 |
\ empty\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ queue{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
|
haftmann@29735
|
77 |
\ \ {\isachardoublequoteopen}empty\ {\isacharequal}\ AQueue\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharbrackleft}{\isacharbrackright}{\isachardoublequoteclose}\isanewline
|
haftmann@28447
|
78 |
\isanewline
|
haftmann@28447
|
79 |
\isacommand{primrec}\isamarkupfalse%
|
haftmann@28447
|
80 |
\ enqueue\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a\ queue\ {\isasymRightarrow}\ {\isacharprime}a\ queue{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
|
haftmann@29735
|
81 |
\ \ {\isachardoublequoteopen}enqueue\ x\ {\isacharparenleft}AQueue\ xs\ ys{\isacharparenright}\ {\isacharequal}\ AQueue\ {\isacharparenleft}x\ {\isacharhash}\ xs{\isacharparenright}\ ys{\isachardoublequoteclose}\isanewline
|
haftmann@28447
|
82 |
\isanewline
|
haftmann@28447
|
83 |
\isacommand{fun}\isamarkupfalse%
|
haftmann@28447
|
84 |
\ dequeue\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ queue\ {\isasymRightarrow}\ {\isacharprime}a\ option\ {\isasymtimes}\ {\isacharprime}a\ queue{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
|
haftmann@29735
|
85 |
\ \ \ \ {\isachardoublequoteopen}dequeue\ {\isacharparenleft}AQueue\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}None{\isacharcomma}\ AQueue\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}{\isachardoublequoteclose}\isanewline
|
haftmann@29735
|
86 |
\ \ {\isacharbar}\ {\isachardoublequoteopen}dequeue\ {\isacharparenleft}AQueue\ xs\ {\isacharparenleft}y\ {\isacharhash}\ ys{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}Some\ y{\isacharcomma}\ AQueue\ xs\ ys{\isacharparenright}{\isachardoublequoteclose}\isanewline
|
haftmann@29735
|
87 |
\ \ {\isacharbar}\ {\isachardoublequoteopen}dequeue\ {\isacharparenleft}AQueue\ xs\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}\ {\isacharequal}\isanewline
|
haftmann@38670
|
88 |
\ \ \ \ \ \ {\isacharparenleft}case\ rev\ xs\ of\ y\ {\isacharhash}\ ys\ {\isasymRightarrow}\ {\isacharparenleft}Some\ y{\isacharcomma}\ AQueue\ {\isacharbrackleft}{\isacharbrackright}\ ys{\isacharparenright}{\isacharparenright}{\isachardoublequoteclose}\ %
|
haftmann@28564
|
89 |
\endisatagquote
|
haftmann@28564
|
90 |
{\isafoldquote}%
|
haftmann@28447
|
91 |
%
|
haftmann@28564
|
92 |
\isadelimquote
|
haftmann@28447
|
93 |
%
|
haftmann@28564
|
94 |
\endisadelimquote
|
haftmann@28447
|
95 |
%
|
haftmann@38670
|
96 |
\isadeliminvisible
|
haftmann@38670
|
97 |
%
|
haftmann@38670
|
98 |
\endisadeliminvisible
|
haftmann@38670
|
99 |
%
|
haftmann@38670
|
100 |
\isataginvisible
|
haftmann@38670
|
101 |
%
|
haftmann@38670
|
102 |
\endisataginvisible
|
haftmann@38670
|
103 |
{\isafoldinvisible}%
|
haftmann@38670
|
104 |
%
|
haftmann@38670
|
105 |
\isadeliminvisible
|
haftmann@38670
|
106 |
%
|
haftmann@38670
|
107 |
\endisadeliminvisible
|
haftmann@38670
|
108 |
%
|
haftmann@28447
|
109 |
\begin{isamarkuptext}%
|
haftmann@28447
|
110 |
\noindent Then we can generate code e.g.~for \isa{SML} as follows:%
|
haftmann@28447
|
111 |
\end{isamarkuptext}%
|
haftmann@28447
|
112 |
\isamarkuptrue%
|
haftmann@28447
|
113 |
%
|
haftmann@28564
|
114 |
\isadelimquote
|
haftmann@28447
|
115 |
%
|
haftmann@28564
|
116 |
\endisadelimquote
|
haftmann@28447
|
117 |
%
|
haftmann@28564
|
118 |
\isatagquote
|
haftmann@28447
|
119 |
\isacommand{export{\isacharunderscore}code}\isamarkupfalse%
|
haftmann@28447
|
120 |
\ empty\ dequeue\ enqueue\ \isakeyword{in}\ SML\isanewline
|
haftmann@28447
|
121 |
\ \ \isakeyword{module{\isacharunderscore}name}\ Example\ \isakeyword{file}\ {\isachardoublequoteopen}examples{\isacharslash}example{\isachardot}ML{\isachardoublequoteclose}%
|
haftmann@28564
|
122 |
\endisatagquote
|
haftmann@28564
|
123 |
{\isafoldquote}%
|
haftmann@28447
|
124 |
%
|
haftmann@28564
|
125 |
\isadelimquote
|
haftmann@28447
|
126 |
%
|
haftmann@28564
|
127 |
\endisadelimquote
|
haftmann@28447
|
128 |
%
|
haftmann@28447
|
129 |
\begin{isamarkuptext}%
|
haftmann@28447
|
130 |
\noindent resulting in the following code:%
|
haftmann@28447
|
131 |
\end{isamarkuptext}%
|
haftmann@28447
|
132 |
\isamarkuptrue%
|
haftmann@28447
|
133 |
%
|
haftmann@28564
|
134 |
\isadelimquote
|
haftmann@28447
|
135 |
%
|
haftmann@28564
|
136 |
\endisadelimquote
|
haftmann@28447
|
137 |
%
|
haftmann@28564
|
138 |
\isatagquote
|
haftmann@28447
|
139 |
%
|
haftmann@28447
|
140 |
\begin{isamarkuptext}%
|
haftmann@28727
|
141 |
\isatypewriter%
|
haftmann@28447
|
142 |
\noindent%
|
paulson@34155
|
143 |
\hspace*{0pt}structure Example :~sig\\
|
haftmann@34179
|
144 |
\hspace*{0pt} ~val foldl :~('a -> 'b -> 'a) -> 'a -> 'b list -> 'a\\
|
paulson@34155
|
145 |
\hspace*{0pt} ~val rev :~'a list -> 'a list\\
|
haftmann@34179
|
146 |
\hspace*{0pt} ~datatype 'a queue = AQueue of 'a list * 'a list\\
|
paulson@34155
|
147 |
\hspace*{0pt} ~val empty :~'a queue\\
|
paulson@34155
|
148 |
\hspace*{0pt} ~val dequeue :~'a queue -> 'a option * 'a queue\\
|
paulson@34155
|
149 |
\hspace*{0pt} ~val enqueue :~'a -> 'a queue -> 'a queue\\
|
paulson@34155
|
150 |
\hspace*{0pt}end = struct\\
|
haftmann@28714
|
151 |
\hspace*{0pt}\\
|
haftmann@28714
|
152 |
\hspace*{0pt}fun foldl f a [] = a\\
|
haftmann@34179
|
153 |
\hspace*{0pt} ~| foldl f a (x ::~xs) = foldl f (f a x) xs;\\
|
haftmann@28714
|
154 |
\hspace*{0pt}\\
|
haftmann@34179
|
155 |
\hspace*{0pt}fun rev xs = foldl (fn xsa => fn x => x ::~xsa) [] xs;\\
|
haftmann@28714
|
156 |
\hspace*{0pt}\\
|
haftmann@34179
|
157 |
\hspace*{0pt}datatype 'a queue = AQueue of 'a list * 'a list;\\
|
haftmann@28714
|
158 |
\hspace*{0pt}\\
|
haftmann@34179
|
159 |
\hspace*{0pt}val empty :~'a queue = AQueue ([],~[]);\\
|
haftmann@28714
|
160 |
\hspace*{0pt}\\
|
haftmann@34179
|
161 |
\hspace*{0pt}fun dequeue (AQueue ([],~[])) = (NONE,~AQueue ([],~[]))\\
|
haftmann@34179
|
162 |
\hspace*{0pt} ~| dequeue (AQueue (xs,~y ::~ys)) = (SOME y,~AQueue (xs,~ys))\\
|
haftmann@34179
|
163 |
\hspace*{0pt} ~| dequeue (AQueue (v ::~va,~[])) =\\
|
haftmann@28714
|
164 |
\hspace*{0pt} ~~~let\\
|
haftmann@34179
|
165 |
\hspace*{0pt} ~~~~~val y ::~ys = rev (v ::~va);\\
|
haftmann@28714
|
166 |
\hspace*{0pt} ~~~in\\
|
haftmann@34179
|
167 |
\hspace*{0pt} ~~~~~(SOME y,~AQueue ([],~ys))\\
|
haftmann@28714
|
168 |
\hspace*{0pt} ~~~end;\\
|
haftmann@28714
|
169 |
\hspace*{0pt}\\
|
haftmann@34179
|
170 |
\hspace*{0pt}fun enqueue x (AQueue (xs,~ys)) = AQueue (x ::~xs,~ys);\\
|
haftmann@28714
|
171 |
\hspace*{0pt}\\
|
wenzelm@29297
|
172 |
\hspace*{0pt}end;~(*struct Example*)%
|
haftmann@28447
|
173 |
\end{isamarkuptext}%
|
haftmann@28447
|
174 |
\isamarkuptrue%
|
haftmann@28447
|
175 |
%
|
haftmann@28564
|
176 |
\endisatagquote
|
haftmann@28564
|
177 |
{\isafoldquote}%
|
haftmann@28447
|
178 |
%
|
haftmann@28564
|
179 |
\isadelimquote
|
haftmann@28447
|
180 |
%
|
haftmann@28564
|
181 |
\endisadelimquote
|
haftmann@28447
|
182 |
%
|
haftmann@28447
|
183 |
\begin{isamarkuptext}%
|
haftmann@38670
|
184 |
\noindent The \hyperlink{command.export-code}{\mbox{\isa{\isacommand{export{\isacharunderscore}code}}}} command takes a space-separated
|
haftmann@38670
|
185 |
list of constants for which code shall be generated; anything else
|
haftmann@38670
|
186 |
needed for those is added implicitly. Then follows a target
|
haftmann@38670
|
187 |
language identifier and a freely chosen module name. A file name
|
haftmann@38670
|
188 |
denotes the destination to store the generated code. Note that the
|
haftmann@38670
|
189 |
semantics of the destination depends on the target language: for
|
haftmann@38670
|
190 |
\isa{SML} and \isa{OCaml} it denotes a \emph{file}, for \isa{Haskell} it denotes a \emph{directory} where a file named as the
|
haftmann@38670
|
191 |
module name (with extension \isa{{\isachardot}hs}) is written:%
|
haftmann@28447
|
192 |
\end{isamarkuptext}%
|
haftmann@28447
|
193 |
\isamarkuptrue%
|
haftmann@28447
|
194 |
%
|
haftmann@28564
|
195 |
\isadelimquote
|
haftmann@28447
|
196 |
%
|
haftmann@28564
|
197 |
\endisadelimquote
|
haftmann@28447
|
198 |
%
|
haftmann@28564
|
199 |
\isatagquote
|
haftmann@28447
|
200 |
\isacommand{export{\isacharunderscore}code}\isamarkupfalse%
|
haftmann@28447
|
201 |
\ empty\ dequeue\ enqueue\ \isakeyword{in}\ Haskell\isanewline
|
haftmann@28447
|
202 |
\ \ \isakeyword{module{\isacharunderscore}name}\ Example\ \isakeyword{file}\ {\isachardoublequoteopen}examples{\isacharslash}{\isachardoublequoteclose}%
|
haftmann@28564
|
203 |
\endisatagquote
|
haftmann@28564
|
204 |
{\isafoldquote}%
|
haftmann@28447
|
205 |
%
|
haftmann@28564
|
206 |
\isadelimquote
|
haftmann@28447
|
207 |
%
|
haftmann@28564
|
208 |
\endisadelimquote
|
haftmann@28447
|
209 |
%
|
haftmann@28447
|
210 |
\begin{isamarkuptext}%
|
haftmann@38670
|
211 |
\noindent This is the corresponding code:%
|
haftmann@28447
|
212 |
\end{isamarkuptext}%
|
haftmann@28447
|
213 |
\isamarkuptrue%
|
haftmann@28447
|
214 |
%
|
haftmann@28564
|
215 |
\isadelimquote
|
haftmann@28447
|
216 |
%
|
haftmann@28564
|
217 |
\endisadelimquote
|
haftmann@28447
|
218 |
%
|
haftmann@28564
|
219 |
\isatagquote
|
haftmann@28447
|
220 |
%
|
haftmann@28447
|
221 |
\begin{isamarkuptext}%
|
haftmann@28727
|
222 |
\isatypewriter%
|
haftmann@28447
|
223 |
\noindent%
|
haftmann@28714
|
224 |
\hspace*{0pt}module Example where {\char123}\\
|
haftmann@28714
|
225 |
\hspace*{0pt}\\
|
haftmann@29735
|
226 |
\hspace*{0pt}data Queue a = AQueue [a] [a];\\
|
haftmann@28714
|
227 |
\hspace*{0pt}\\
|
wenzelm@29297
|
228 |
\hspace*{0pt}empty ::~forall a.~Queue a;\\
|
haftmann@29735
|
229 |
\hspace*{0pt}empty = AQueue [] [];\\
|
haftmann@28714
|
230 |
\hspace*{0pt}\\
|
wenzelm@29297
|
231 |
\hspace*{0pt}dequeue ::~forall a.~Queue a -> (Maybe a,~Queue a);\\
|
haftmann@34179
|
232 |
\hspace*{0pt}dequeue (AQueue [] []) = (Nothing,~AQueue [] []);\\
|
haftmann@34179
|
233 |
\hspace*{0pt}dequeue (AQueue xs (y :~ys)) = (Just y,~AQueue xs ys);\\
|
haftmann@34179
|
234 |
\hspace*{0pt}dequeue (AQueue (v :~va) []) =\\
|
haftmann@31848
|
235 |
\hspace*{0pt} ~let {\char123}\\
|
haftmann@37610
|
236 |
\hspace*{0pt} ~~~(y :~ys) = reverse (v :~va);\\
|
haftmann@31848
|
237 |
\hspace*{0pt} ~{\char125}~in (Just y,~AQueue [] ys);\\
|
haftmann@28714
|
238 |
\hspace*{0pt}\\
|
wenzelm@29297
|
239 |
\hspace*{0pt}enqueue ::~forall a.~a -> Queue a -> Queue a;\\
|
haftmann@34179
|
240 |
\hspace*{0pt}enqueue x (AQueue xs ys) = AQueue (x :~xs) ys;\\
|
haftmann@28714
|
241 |
\hspace*{0pt}\\
|
haftmann@28714
|
242 |
\hspace*{0pt}{\char125}%
|
haftmann@28447
|
243 |
\end{isamarkuptext}%
|
haftmann@28447
|
244 |
\isamarkuptrue%
|
haftmann@28447
|
245 |
%
|
haftmann@28564
|
246 |
\endisatagquote
|
haftmann@28564
|
247 |
{\isafoldquote}%
|
haftmann@28447
|
248 |
%
|
haftmann@28564
|
249 |
\isadelimquote
|
haftmann@28447
|
250 |
%
|
haftmann@28564
|
251 |
\endisadelimquote
|
haftmann@28447
|
252 |
%
|
haftmann@28447
|
253 |
\begin{isamarkuptext}%
|
haftmann@38670
|
254 |
\noindent For more details about \hyperlink{command.export-code}{\mbox{\isa{\isacommand{export{\isacharunderscore}code}}}} see
|
haftmann@38670
|
255 |
\secref{sec:further}.%
|
haftmann@28447
|
256 |
\end{isamarkuptext}%
|
haftmann@28447
|
257 |
\isamarkuptrue%
|
haftmann@28447
|
258 |
%
|
haftmann@38670
|
259 |
\isamarkupsubsection{Type classes%
|
haftmann@38628
|
260 |
}
|
haftmann@38628
|
261 |
\isamarkuptrue%
|
haftmann@38628
|
262 |
%
|
haftmann@38628
|
263 |
\begin{isamarkuptext}%
|
haftmann@38670
|
264 |
Code can also be generated from type classes in a Haskell-like
|
haftmann@38670
|
265 |
manner. For illustration here an example from abstract algebra:%
|
haftmann@38628
|
266 |
\end{isamarkuptext}%
|
haftmann@38628
|
267 |
\isamarkuptrue%
|
haftmann@38628
|
268 |
%
|
haftmann@38670
|
269 |
\isadelimquote
|
haftmann@38670
|
270 |
%
|
haftmann@38670
|
271 |
\endisadelimquote
|
haftmann@38670
|
272 |
%
|
haftmann@38670
|
273 |
\isatagquote
|
haftmann@38670
|
274 |
\isacommand{class}\isamarkupfalse%
|
haftmann@38670
|
275 |
\ semigroup\ {\isacharequal}\isanewline
|
haftmann@38670
|
276 |
\ \ \isakeyword{fixes}\ mult\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a{\isachardoublequoteclose}\ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequoteopen}{\isasymotimes}{\isachardoublequoteclose}\ {\isadigit{7}}{\isadigit{0}}{\isacharparenright}\isanewline
|
haftmann@38670
|
277 |
\ \ \isakeyword{assumes}\ assoc{\isacharcolon}\ {\isachardoublequoteopen}{\isacharparenleft}x\ {\isasymotimes}\ y{\isacharparenright}\ {\isasymotimes}\ z\ {\isacharequal}\ x\ {\isasymotimes}\ {\isacharparenleft}y\ {\isasymotimes}\ z{\isacharparenright}{\isachardoublequoteclose}\isanewline
|
haftmann@38670
|
278 |
\isanewline
|
haftmann@38670
|
279 |
\isacommand{class}\isamarkupfalse%
|
haftmann@38670
|
280 |
\ monoid\ {\isacharequal}\ semigroup\ {\isacharplus}\isanewline
|
haftmann@38670
|
281 |
\ \ \isakeyword{fixes}\ neutral\ {\isacharcolon}{\isacharcolon}\ {\isacharprime}a\ {\isacharparenleft}{\isachardoublequoteopen}{\isasymone}{\isachardoublequoteclose}{\isacharparenright}\isanewline
|
haftmann@38670
|
282 |
\ \ \isakeyword{assumes}\ neutl{\isacharcolon}\ {\isachardoublequoteopen}{\isasymone}\ {\isasymotimes}\ x\ {\isacharequal}\ x{\isachardoublequoteclose}\isanewline
|
haftmann@38670
|
283 |
\ \ \ \ \isakeyword{and}\ neutr{\isacharcolon}\ {\isachardoublequoteopen}x\ {\isasymotimes}\ {\isasymone}\ {\isacharequal}\ x{\isachardoublequoteclose}\isanewline
|
haftmann@38670
|
284 |
\isanewline
|
haftmann@38670
|
285 |
\isacommand{instantiation}\isamarkupfalse%
|
haftmann@38670
|
286 |
\ nat\ {\isacharcolon}{\isacharcolon}\ monoid\isanewline
|
haftmann@38670
|
287 |
\isakeyword{begin}\isanewline
|
haftmann@38670
|
288 |
\isanewline
|
haftmann@38670
|
289 |
\isacommand{primrec}\isamarkupfalse%
|
haftmann@38670
|
290 |
\ mult{\isacharunderscore}nat\ \isakeyword{where}\isanewline
|
haftmann@38670
|
291 |
\ \ \ \ {\isachardoublequoteopen}{\isadigit{0}}\ {\isasymotimes}\ n\ {\isacharequal}\ {\isacharparenleft}{\isadigit{0}}{\isasymColon}nat{\isacharparenright}{\isachardoublequoteclose}\isanewline
|
haftmann@38670
|
292 |
\ \ {\isacharbar}\ {\isachardoublequoteopen}Suc\ m\ {\isasymotimes}\ n\ {\isacharequal}\ n\ {\isacharplus}\ m\ {\isasymotimes}\ n{\isachardoublequoteclose}\isanewline
|
haftmann@38670
|
293 |
\isanewline
|
haftmann@38670
|
294 |
\isacommand{definition}\isamarkupfalse%
|
haftmann@38670
|
295 |
\ neutral{\isacharunderscore}nat\ \isakeyword{where}\isanewline
|
haftmann@38670
|
296 |
\ \ {\isachardoublequoteopen}{\isasymone}\ {\isacharequal}\ Suc\ {\isadigit{0}}{\isachardoublequoteclose}\isanewline
|
haftmann@38670
|
297 |
\isanewline
|
haftmann@38670
|
298 |
\isacommand{lemma}\isamarkupfalse%
|
haftmann@38670
|
299 |
\ add{\isacharunderscore}mult{\isacharunderscore}distrib{\isacharcolon}\isanewline
|
haftmann@38670
|
300 |
\ \ \isakeyword{fixes}\ n\ m\ q\ {\isacharcolon}{\isacharcolon}\ nat\isanewline
|
haftmann@38670
|
301 |
\ \ \isakeyword{shows}\ {\isachardoublequoteopen}{\isacharparenleft}n\ {\isacharplus}\ m{\isacharparenright}\ {\isasymotimes}\ q\ {\isacharequal}\ n\ {\isasymotimes}\ q\ {\isacharplus}\ m\ {\isasymotimes}\ q{\isachardoublequoteclose}\isanewline
|
haftmann@38670
|
302 |
\ \ \isacommand{by}\isamarkupfalse%
|
haftmann@38670
|
303 |
\ {\isacharparenleft}induct\ n{\isacharparenright}\ simp{\isacharunderscore}all\isanewline
|
haftmann@38670
|
304 |
\isanewline
|
haftmann@38670
|
305 |
\isacommand{instance}\isamarkupfalse%
|
haftmann@38670
|
306 |
\ \isacommand{proof}\isamarkupfalse%
|
haftmann@38670
|
307 |
\isanewline
|
haftmann@38670
|
308 |
\ \ \isacommand{fix}\isamarkupfalse%
|
haftmann@38670
|
309 |
\ m\ n\ q\ {\isacharcolon}{\isacharcolon}\ nat\isanewline
|
haftmann@38670
|
310 |
\ \ \isacommand{show}\isamarkupfalse%
|
haftmann@38670
|
311 |
\ {\isachardoublequoteopen}m\ {\isasymotimes}\ n\ {\isasymotimes}\ q\ {\isacharequal}\ m\ {\isasymotimes}\ {\isacharparenleft}n\ {\isasymotimes}\ q{\isacharparenright}{\isachardoublequoteclose}\isanewline
|
haftmann@38670
|
312 |
\ \ \ \ \isacommand{by}\isamarkupfalse%
|
haftmann@38670
|
313 |
\ {\isacharparenleft}induct\ m{\isacharparenright}\ {\isacharparenleft}simp{\isacharunderscore}all\ add{\isacharcolon}\ add{\isacharunderscore}mult{\isacharunderscore}distrib{\isacharparenright}\isanewline
|
haftmann@38670
|
314 |
\ \ \isacommand{show}\isamarkupfalse%
|
haftmann@38670
|
315 |
\ {\isachardoublequoteopen}{\isasymone}\ {\isasymotimes}\ n\ {\isacharequal}\ n{\isachardoublequoteclose}\isanewline
|
haftmann@38670
|
316 |
\ \ \ \ \isacommand{by}\isamarkupfalse%
|
haftmann@38670
|
317 |
\ {\isacharparenleft}simp\ add{\isacharcolon}\ neutral{\isacharunderscore}nat{\isacharunderscore}def{\isacharparenright}\isanewline
|
haftmann@38670
|
318 |
\ \ \isacommand{show}\isamarkupfalse%
|
haftmann@38670
|
319 |
\ {\isachardoublequoteopen}m\ {\isasymotimes}\ {\isasymone}\ {\isacharequal}\ m{\isachardoublequoteclose}\isanewline
|
haftmann@38670
|
320 |
\ \ \ \ \isacommand{by}\isamarkupfalse%
|
haftmann@38670
|
321 |
\ {\isacharparenleft}induct\ m{\isacharparenright}\ {\isacharparenleft}simp{\isacharunderscore}all\ add{\isacharcolon}\ neutral{\isacharunderscore}nat{\isacharunderscore}def{\isacharparenright}\isanewline
|
haftmann@38670
|
322 |
\isacommand{qed}\isamarkupfalse%
|
haftmann@38670
|
323 |
\isanewline
|
haftmann@38670
|
324 |
\isanewline
|
haftmann@38670
|
325 |
\isacommand{end}\isamarkupfalse%
|
haftmann@38670
|
326 |
%
|
haftmann@38670
|
327 |
\endisatagquote
|
haftmann@38670
|
328 |
{\isafoldquote}%
|
haftmann@38670
|
329 |
%
|
haftmann@38670
|
330 |
\isadelimquote
|
haftmann@38670
|
331 |
%
|
haftmann@38670
|
332 |
\endisadelimquote
|
haftmann@38670
|
333 |
%
|
haftmann@38670
|
334 |
\begin{isamarkuptext}%
|
haftmann@38670
|
335 |
\noindent We define the natural operation of the natural numbers
|
haftmann@38670
|
336 |
on monoids:%
|
haftmann@38670
|
337 |
\end{isamarkuptext}%
|
haftmann@38670
|
338 |
\isamarkuptrue%
|
haftmann@38670
|
339 |
%
|
haftmann@38670
|
340 |
\isadelimquote
|
haftmann@38670
|
341 |
%
|
haftmann@38670
|
342 |
\endisadelimquote
|
haftmann@38670
|
343 |
%
|
haftmann@38670
|
344 |
\isatagquote
|
haftmann@38670
|
345 |
\isacommand{primrec}\isamarkupfalse%
|
haftmann@38670
|
346 |
\ {\isacharparenleft}\isakeyword{in}\ monoid{\isacharparenright}\ pow\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
|
haftmann@38670
|
347 |
\ \ \ \ {\isachardoublequoteopen}pow\ {\isadigit{0}}\ a\ {\isacharequal}\ {\isasymone}{\isachardoublequoteclose}\isanewline
|
haftmann@38670
|
348 |
\ \ {\isacharbar}\ {\isachardoublequoteopen}pow\ {\isacharparenleft}Suc\ n{\isacharparenright}\ a\ {\isacharequal}\ a\ {\isasymotimes}\ pow\ n\ a{\isachardoublequoteclose}%
|
haftmann@38670
|
349 |
\endisatagquote
|
haftmann@38670
|
350 |
{\isafoldquote}%
|
haftmann@38670
|
351 |
%
|
haftmann@38670
|
352 |
\isadelimquote
|
haftmann@38670
|
353 |
%
|
haftmann@38670
|
354 |
\endisadelimquote
|
haftmann@38670
|
355 |
%
|
haftmann@38670
|
356 |
\begin{isamarkuptext}%
|
haftmann@38670
|
357 |
\noindent This we use to define the discrete exponentiation
|
haftmann@38670
|
358 |
function:%
|
haftmann@38670
|
359 |
\end{isamarkuptext}%
|
haftmann@38670
|
360 |
\isamarkuptrue%
|
haftmann@38670
|
361 |
%
|
haftmann@38670
|
362 |
\isadelimquote
|
haftmann@38670
|
363 |
%
|
haftmann@38670
|
364 |
\endisadelimquote
|
haftmann@38670
|
365 |
%
|
haftmann@38670
|
366 |
\isatagquote
|
haftmann@38670
|
367 |
\isacommand{definition}\isamarkupfalse%
|
haftmann@38670
|
368 |
\ bexp\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymRightarrow}\ nat{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
|
haftmann@38670
|
369 |
\ \ {\isachardoublequoteopen}bexp\ n\ {\isacharequal}\ pow\ n\ {\isacharparenleft}Suc\ {\isacharparenleft}Suc\ {\isadigit{0}}{\isacharparenright}{\isacharparenright}{\isachardoublequoteclose}%
|
haftmann@38670
|
370 |
\endisatagquote
|
haftmann@38670
|
371 |
{\isafoldquote}%
|
haftmann@38670
|
372 |
%
|
haftmann@38670
|
373 |
\isadelimquote
|
haftmann@38670
|
374 |
%
|
haftmann@38670
|
375 |
\endisadelimquote
|
haftmann@38670
|
376 |
%
|
haftmann@38670
|
377 |
\begin{isamarkuptext}%
|
haftmann@38670
|
378 |
\noindent The corresponding code in Haskell uses that language's
|
haftmann@38670
|
379 |
native classes:%
|
haftmann@38670
|
380 |
\end{isamarkuptext}%
|
haftmann@38670
|
381 |
\isamarkuptrue%
|
haftmann@38670
|
382 |
%
|
haftmann@38670
|
383 |
\isadelimquote
|
haftmann@38670
|
384 |
%
|
haftmann@38670
|
385 |
\endisadelimquote
|
haftmann@38670
|
386 |
%
|
haftmann@38670
|
387 |
\isatagquote
|
haftmann@38670
|
388 |
%
|
haftmann@38670
|
389 |
\begin{isamarkuptext}%
|
haftmann@38670
|
390 |
\isatypewriter%
|
haftmann@38670
|
391 |
\noindent%
|
haftmann@38670
|
392 |
\hspace*{0pt}module Example where {\char123}\\
|
haftmann@38670
|
393 |
\hspace*{0pt}\\
|
haftmann@38670
|
394 |
\hspace*{0pt}data Nat = Zero{\char95}nat | Suc Nat;\\
|
haftmann@38670
|
395 |
\hspace*{0pt}\\
|
haftmann@38670
|
396 |
\hspace*{0pt}plus{\char95}nat ::~Nat -> Nat -> Nat;\\
|
haftmann@38670
|
397 |
\hspace*{0pt}plus{\char95}nat (Suc m) n = plus{\char95}nat m (Suc n);\\
|
haftmann@38670
|
398 |
\hspace*{0pt}plus{\char95}nat Zero{\char95}nat n = n;\\
|
haftmann@38670
|
399 |
\hspace*{0pt}\\
|
haftmann@38670
|
400 |
\hspace*{0pt}class Semigroup a where {\char123}\\
|
haftmann@38670
|
401 |
\hspace*{0pt} ~mult ::~a -> a -> a;\\
|
haftmann@38670
|
402 |
\hspace*{0pt}{\char125};\\
|
haftmann@38670
|
403 |
\hspace*{0pt}\\
|
haftmann@38670
|
404 |
\hspace*{0pt}class (Semigroup a) => Monoid a where {\char123}\\
|
haftmann@38670
|
405 |
\hspace*{0pt} ~neutral ::~a;\\
|
haftmann@38670
|
406 |
\hspace*{0pt}{\char125};\\
|
haftmann@38670
|
407 |
\hspace*{0pt}\\
|
haftmann@38670
|
408 |
\hspace*{0pt}pow ::~forall a.~(Monoid a) => Nat -> a -> a;\\
|
haftmann@38670
|
409 |
\hspace*{0pt}pow Zero{\char95}nat a = neutral;\\
|
haftmann@38670
|
410 |
\hspace*{0pt}pow (Suc n) a = mult a (pow n a);\\
|
haftmann@38670
|
411 |
\hspace*{0pt}\\
|
haftmann@38670
|
412 |
\hspace*{0pt}mult{\char95}nat ::~Nat -> Nat -> Nat;\\
|
haftmann@38670
|
413 |
\hspace*{0pt}mult{\char95}nat Zero{\char95}nat n = Zero{\char95}nat;\\
|
haftmann@38670
|
414 |
\hspace*{0pt}mult{\char95}nat (Suc m) n = plus{\char95}nat n (mult{\char95}nat m n);\\
|
haftmann@38670
|
415 |
\hspace*{0pt}\\
|
haftmann@38670
|
416 |
\hspace*{0pt}neutral{\char95}nat ::~Nat;\\
|
haftmann@38670
|
417 |
\hspace*{0pt}neutral{\char95}nat = Suc Zero{\char95}nat;\\
|
haftmann@38670
|
418 |
\hspace*{0pt}\\
|
haftmann@38670
|
419 |
\hspace*{0pt}instance Semigroup Nat where {\char123}\\
|
haftmann@38670
|
420 |
\hspace*{0pt} ~mult = mult{\char95}nat;\\
|
haftmann@38670
|
421 |
\hspace*{0pt}{\char125};\\
|
haftmann@38670
|
422 |
\hspace*{0pt}\\
|
haftmann@38670
|
423 |
\hspace*{0pt}instance Monoid Nat where {\char123}\\
|
haftmann@38670
|
424 |
\hspace*{0pt} ~neutral = neutral{\char95}nat;\\
|
haftmann@38670
|
425 |
\hspace*{0pt}{\char125};\\
|
haftmann@38670
|
426 |
\hspace*{0pt}\\
|
haftmann@38670
|
427 |
\hspace*{0pt}bexp ::~Nat -> Nat;\\
|
haftmann@38670
|
428 |
\hspace*{0pt}bexp n = pow n (Suc (Suc Zero{\char95}nat));\\
|
haftmann@38670
|
429 |
\hspace*{0pt}\\
|
haftmann@38670
|
430 |
\hspace*{0pt}{\char125}%
|
haftmann@38670
|
431 |
\end{isamarkuptext}%
|
haftmann@38670
|
432 |
\isamarkuptrue%
|
haftmann@38670
|
433 |
%
|
haftmann@38670
|
434 |
\endisatagquote
|
haftmann@38670
|
435 |
{\isafoldquote}%
|
haftmann@38670
|
436 |
%
|
haftmann@38670
|
437 |
\isadelimquote
|
haftmann@38670
|
438 |
%
|
haftmann@38670
|
439 |
\endisadelimquote
|
haftmann@38670
|
440 |
%
|
haftmann@38670
|
441 |
\begin{isamarkuptext}%
|
haftmann@38670
|
442 |
\noindent This is a convenient place to show how explicit dictionary
|
haftmann@38670
|
443 |
construction manifests in generated code -- the same example in
|
haftmann@38670
|
444 |
\isa{SML}:%
|
haftmann@38670
|
445 |
\end{isamarkuptext}%
|
haftmann@38670
|
446 |
\isamarkuptrue%
|
haftmann@38670
|
447 |
%
|
haftmann@38670
|
448 |
\isadelimquote
|
haftmann@38670
|
449 |
%
|
haftmann@38670
|
450 |
\endisadelimquote
|
haftmann@38670
|
451 |
%
|
haftmann@38670
|
452 |
\isatagquote
|
haftmann@38670
|
453 |
%
|
haftmann@38670
|
454 |
\begin{isamarkuptext}%
|
haftmann@38670
|
455 |
\isatypewriter%
|
haftmann@38670
|
456 |
\noindent%
|
haftmann@38670
|
457 |
\hspace*{0pt}structure Example :~sig\\
|
haftmann@38670
|
458 |
\hspace*{0pt} ~datatype nat = Zero{\char95}nat | Suc of nat\\
|
haftmann@38670
|
459 |
\hspace*{0pt} ~val plus{\char95}nat :~nat -> nat -> nat\\
|
haftmann@38670
|
460 |
\hspace*{0pt} ~type 'a semigroup\\
|
haftmann@38670
|
461 |
\hspace*{0pt} ~val mult :~'a semigroup -> 'a -> 'a -> 'a\\
|
haftmann@38670
|
462 |
\hspace*{0pt} ~type 'a monoid\\
|
haftmann@38670
|
463 |
\hspace*{0pt} ~val semigroup{\char95}monoid :~'a monoid -> 'a semigroup\\
|
haftmann@38670
|
464 |
\hspace*{0pt} ~val neutral :~'a monoid -> 'a\\
|
haftmann@38670
|
465 |
\hspace*{0pt} ~val pow :~'a monoid -> nat -> 'a -> 'a\\
|
haftmann@38670
|
466 |
\hspace*{0pt} ~val mult{\char95}nat :~nat -> nat -> nat\\
|
haftmann@38670
|
467 |
\hspace*{0pt} ~val neutral{\char95}nat :~nat\\
|
haftmann@38670
|
468 |
\hspace*{0pt} ~val semigroup{\char95}nat :~nat semigroup\\
|
haftmann@38670
|
469 |
\hspace*{0pt} ~val monoid{\char95}nat :~nat monoid\\
|
haftmann@38670
|
470 |
\hspace*{0pt} ~val bexp :~nat -> nat\\
|
haftmann@38670
|
471 |
\hspace*{0pt}end = struct\\
|
haftmann@38670
|
472 |
\hspace*{0pt}\\
|
haftmann@38670
|
473 |
\hspace*{0pt}datatype nat = Zero{\char95}nat | Suc of nat;\\
|
haftmann@38670
|
474 |
\hspace*{0pt}\\
|
haftmann@38670
|
475 |
\hspace*{0pt}fun plus{\char95}nat (Suc m) n = plus{\char95}nat m (Suc n)\\
|
haftmann@38670
|
476 |
\hspace*{0pt} ~| plus{\char95}nat Zero{\char95}nat n = n;\\
|
haftmann@38670
|
477 |
\hspace*{0pt}\\
|
haftmann@38670
|
478 |
\hspace*{0pt}type 'a semigroup = {\char123}mult :~'a -> 'a -> 'a{\char125};\\
|
haftmann@38670
|
479 |
\hspace*{0pt}val mult = {\char35}mult :~'a semigroup -> 'a -> 'a -> 'a;\\
|
haftmann@38670
|
480 |
\hspace*{0pt}\\
|
haftmann@38670
|
481 |
\hspace*{0pt}type 'a monoid = {\char123}semigroup{\char95}monoid :~'a semigroup,~neutral :~'a{\char125};\\
|
haftmann@38670
|
482 |
\hspace*{0pt}val semigroup{\char95}monoid = {\char35}semigroup{\char95}monoid :~'a monoid -> 'a semigroup;\\
|
haftmann@38670
|
483 |
\hspace*{0pt}val neutral = {\char35}neutral :~'a monoid -> 'a;\\
|
haftmann@38670
|
484 |
\hspace*{0pt}\\
|
haftmann@38670
|
485 |
\hspace*{0pt}fun pow A{\char95}~Zero{\char95}nat a = neutral A{\char95}\\
|
haftmann@38670
|
486 |
\hspace*{0pt} ~| pow A{\char95}~(Suc n) a = mult (semigroup{\char95}monoid A{\char95}) a (pow A{\char95}~n a);\\
|
haftmann@38670
|
487 |
\hspace*{0pt}\\
|
haftmann@38670
|
488 |
\hspace*{0pt}fun mult{\char95}nat Zero{\char95}nat n = Zero{\char95}nat\\
|
haftmann@38670
|
489 |
\hspace*{0pt} ~| mult{\char95}nat (Suc m) n = plus{\char95}nat n (mult{\char95}nat m n);\\
|
haftmann@38670
|
490 |
\hspace*{0pt}\\
|
haftmann@38670
|
491 |
\hspace*{0pt}val neutral{\char95}nat :~nat = Suc Zero{\char95}nat;\\
|
haftmann@38670
|
492 |
\hspace*{0pt}\\
|
haftmann@38670
|
493 |
\hspace*{0pt}val semigroup{\char95}nat = {\char123}mult = mult{\char95}nat{\char125}~:~nat semigroup;\\
|
haftmann@38670
|
494 |
\hspace*{0pt}\\
|
haftmann@38670
|
495 |
\hspace*{0pt}val monoid{\char95}nat = {\char123}semigroup{\char95}monoid = semigroup{\char95}nat,~neutral = neutral{\char95}nat{\char125}\\
|
haftmann@38670
|
496 |
\hspace*{0pt} ~:~nat monoid;\\
|
haftmann@38670
|
497 |
\hspace*{0pt}\\
|
haftmann@38670
|
498 |
\hspace*{0pt}fun bexp n = pow monoid{\char95}nat n (Suc (Suc Zero{\char95}nat));\\
|
haftmann@38670
|
499 |
\hspace*{0pt}\\
|
haftmann@38670
|
500 |
\hspace*{0pt}end;~(*struct Example*)%
|
haftmann@38670
|
501 |
\end{isamarkuptext}%
|
haftmann@38670
|
502 |
\isamarkuptrue%
|
haftmann@38670
|
503 |
%
|
haftmann@38670
|
504 |
\endisatagquote
|
haftmann@38670
|
505 |
{\isafoldquote}%
|
haftmann@38670
|
506 |
%
|
haftmann@38670
|
507 |
\isadelimquote
|
haftmann@38670
|
508 |
%
|
haftmann@38670
|
509 |
\endisadelimquote
|
haftmann@38670
|
510 |
%
|
haftmann@38670
|
511 |
\begin{isamarkuptext}%
|
haftmann@38670
|
512 |
\noindent Note the parameters with trailing underscore (\verb|A_|), which are the dictionary parameters.%
|
haftmann@38670
|
513 |
\end{isamarkuptext}%
|
haftmann@38670
|
514 |
\isamarkuptrue%
|
haftmann@38670
|
515 |
%
|
haftmann@38670
|
516 |
\isamarkupsubsection{How to continue from here%
|
haftmann@28447
|
517 |
}
|
haftmann@28447
|
518 |
\isamarkuptrue%
|
haftmann@28447
|
519 |
%
|
haftmann@28447
|
520 |
\begin{isamarkuptext}%
|
haftmann@38670
|
521 |
What you have seen so far should be already enough in a lot of
|
haftmann@38670
|
522 |
cases. If you are content with this, you can quit reading here.
|
haftmann@28447
|
523 |
|
haftmann@38670
|
524 |
Anyway, to understand situations where problems occur or to increase
|
haftmann@38670
|
525 |
the scope of code generation beyond default, it is necessary to gain
|
haftmann@38670
|
526 |
some understanding how the code generator actually works:
|
haftmann@28447
|
527 |
|
haftmann@28447
|
528 |
\begin{itemize}
|
haftmann@28447
|
529 |
|
haftmann@38670
|
530 |
\item The foundations of the code generator are described in
|
haftmann@38670
|
531 |
\secref{sec:foundations}.
|
haftmann@28447
|
532 |
|
haftmann@38670
|
533 |
\item In particular \secref{sec:utterly_wrong} gives hints how to
|
haftmann@38670
|
534 |
debug situations where code generation does not succeed as
|
haftmann@38670
|
535 |
expected.
|
haftmann@28447
|
536 |
|
haftmann@38670
|
537 |
\item The scope and quality of generated code can be increased
|
haftmann@38670
|
538 |
dramatically by applying refinement techniques, which are
|
haftmann@38670
|
539 |
introduced in \secref{sec:refinement}.
|
haftmann@38670
|
540 |
|
haftmann@38670
|
541 |
\item Inductive predicates can be turned executable using an
|
haftmann@38670
|
542 |
extension of the code generator \secref{sec:inductive}.
|
haftmann@38670
|
543 |
|
haftmann@38670
|
544 |
\item You may want to skim over the more technical sections
|
haftmann@38670
|
545 |
\secref{sec:adaptation} and \secref{sec:further}.
|
haftmann@38670
|
546 |
|
haftmann@38670
|
547 |
\item For exhaustive syntax diagrams etc. you should visit the
|
haftmann@38670
|
548 |
Isabelle/Isar Reference Manual \cite{isabelle-isar-ref}.
|
haftmann@28447
|
549 |
|
haftmann@28447
|
550 |
\end{itemize}
|
haftmann@28447
|
551 |
|
haftmann@38670
|
552 |
\bigskip
|
haftmann@38670
|
553 |
|
haftmann@38670
|
554 |
\begin{center}\fbox{\fbox{\begin{minipage}{8cm}
|
haftmann@38670
|
555 |
|
haftmann@38670
|
556 |
\begin{center}\textit{Happy proving, happy hacking!}\end{center}
|
haftmann@38670
|
557 |
|
haftmann@38670
|
558 |
\end{minipage}}}\end{center}
|
haftmann@38670
|
559 |
|
haftmann@38670
|
560 |
\begin{warn}
|
haftmann@38670
|
561 |
There is also a more ancient code generator in Isabelle by Stefan
|
haftmann@38670
|
562 |
Berghofer \cite{Berghofer-Nipkow:2002}. Although its
|
haftmann@38670
|
563 |
functionality is covered by the code generator presented here, it
|
haftmann@38670
|
564 |
will sometimes show up as an artifact. In case of ambiguity, we
|
haftmann@38670
|
565 |
will refer to the framework described here as \isa{generic\ code\ generator}, to the other as \isa{SML\ code\ generator}.
|
haftmann@38670
|
566 |
\end{warn}%
|
haftmann@28447
|
567 |
\end{isamarkuptext}%
|
haftmann@28447
|
568 |
\isamarkuptrue%
|
haftmann@28447
|
569 |
%
|
haftmann@28447
|
570 |
\isadelimtheory
|
haftmann@28447
|
571 |
%
|
haftmann@28447
|
572 |
\endisadelimtheory
|
haftmann@28447
|
573 |
%
|
haftmann@28447
|
574 |
\isatagtheory
|
haftmann@28447
|
575 |
\isacommand{end}\isamarkupfalse%
|
haftmann@28447
|
576 |
%
|
haftmann@28447
|
577 |
\endisatagtheory
|
haftmann@28447
|
578 |
{\isafoldtheory}%
|
haftmann@28447
|
579 |
%
|
haftmann@28447
|
580 |
\isadelimtheory
|
haftmann@28447
|
581 |
%
|
haftmann@28447
|
582 |
\endisadelimtheory
|
haftmann@28447
|
583 |
\isanewline
|
haftmann@28447
|
584 |
\end{isabellebody}%
|
haftmann@28447
|
585 |
%%% Local Variables:
|
haftmann@28447
|
586 |
%%% mode: latex
|
haftmann@28447
|
587 |
%%% TeX-master: "root"
|
haftmann@28447
|
588 |
%%% End:
|