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