doc-src/Codegen/Thy/document/Introduction.tex
author haftmann
Mon, 27 Sep 2010 16:27:31 +0200
changeset 39745 3aa2bc9c5478
parent 39683 f75a01ee6c41
child 40406 313a24b66a8d
permissions -rw-r--r--
combine quote and typewriter/tt tag
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
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   136
\isadelimquotetypewriter
28447
haftmann
parents:
diff changeset
   137
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   138
\endisadelimquotetypewriter
28447
haftmann
parents:
diff changeset
   139
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   140
\isatagquotetypewriter
28447
haftmann
parents:
diff changeset
   141
%
haftmann
parents:
diff changeset
   142
\begin{isamarkuptext}%
39683
f75a01ee6c41 prefer typewrite tag over raw latex environment
haftmann
parents: 39664
diff changeset
   143
structure\ Example\ {\isacharcolon}\ sig\isanewline
39664
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   144
\ \ val\ id\ {\isacharcolon}\ {\isacharprime}a\ {\isacharminus}{\isachargreater}\ {\isacharprime}a\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   145
\ \ val\ fold\ {\isacharcolon}\ {\isacharparenleft}{\isacharprime}a\ {\isacharminus}{\isachargreater}\ {\isacharprime}b\ {\isacharminus}{\isachargreater}\ {\isacharprime}b{\isacharparenright}\ {\isacharminus}{\isachargreater}\ {\isacharprime}a\ list\ {\isacharminus}{\isachargreater}\ {\isacharprime}b\ {\isacharminus}{\isachargreater}\ {\isacharprime}b\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   146
\ \ val\ rev\ {\isacharcolon}\ {\isacharprime}a\ list\ {\isacharminus}{\isachargreater}\ {\isacharprime}a\ list\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   147
\ \ datatype\ {\isacharprime}a\ queue\ {\isacharequal}\ AQueue\ of\ {\isacharprime}a\ list\ {\isacharasterisk}\ {\isacharprime}a\ list\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   148
\ \ val\ empty\ {\isacharcolon}\ {\isacharprime}a\ queue\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   149
\ \ val\ dequeue\ {\isacharcolon}\ {\isacharprime}a\ queue\ {\isacharminus}{\isachargreater}\ {\isacharprime}a\ option\ {\isacharasterisk}\ {\isacharprime}a\ queue\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   150
\ \ val\ enqueue\ {\isacharcolon}\ {\isacharprime}a\ {\isacharminus}{\isachargreater}\ {\isacharprime}a\ queue\ {\isacharminus}{\isachargreater}\ {\isacharprime}a\ queue\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   151
end\ {\isacharequal}\ struct\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   152
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   153
fun\ id\ x\ {\isacharequal}\ {\isacharparenleft}fn\ xa\ {\isacharequal}{\isachargreater}\ xa{\isacharparenright}\ x{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   154
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   155
fun\ fold\ f\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharequal}\ id\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   156
\ \ {\isacharbar}\ fold\ f\ {\isacharparenleft}x\ {\isacharcolon}{\isacharcolon}\ xs{\isacharparenright}\ {\isacharequal}\ fold\ f\ xs\ o\ f\ x{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   157
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   158
fun\ rev\ xs\ {\isacharequal}\ fold\ {\isacharparenleft}fn\ a\ {\isacharequal}{\isachargreater}\ fn\ b\ {\isacharequal}{\isachargreater}\ a\ {\isacharcolon}{\isacharcolon}\ b{\isacharparenright}\ xs\ {\isacharbrackleft}{\isacharbrackright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   159
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   160
datatype\ {\isacharprime}a\ queue\ {\isacharequal}\ AQueue\ of\ {\isacharprime}a\ list\ {\isacharasterisk}\ {\isacharprime}a\ list{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   161
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   162
val\ empty\ {\isacharcolon}\ {\isacharprime}a\ queue\ {\isacharequal}\ AQueue\ {\isacharparenleft}{\isacharbrackleft}{\isacharbrackright}{\isacharcomma}\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   163
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   164
fun\ dequeue\ {\isacharparenleft}AQueue\ {\isacharparenleft}{\isacharbrackleft}{\isacharbrackright}{\isacharcomma}\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}NONE{\isacharcomma}\ AQueue\ {\isacharparenleft}{\isacharbrackleft}{\isacharbrackright}{\isacharcomma}\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}{\isacharparenright}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   165
\ \ {\isacharbar}\ dequeue\ {\isacharparenleft}AQueue\ {\isacharparenleft}xs{\isacharcomma}\ y\ {\isacharcolon}{\isacharcolon}\ ys{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}SOME\ y{\isacharcomma}\ AQueue\ {\isacharparenleft}xs{\isacharcomma}\ ys{\isacharparenright}{\isacharparenright}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   166
\ \ {\isacharbar}\ dequeue\ {\isacharparenleft}AQueue\ {\isacharparenleft}v\ {\isacharcolon}{\isacharcolon}\ va{\isacharcomma}\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}{\isacharparenright}\ {\isacharequal}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   167
\ \ \ \ let\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   168
\ \ \ \ \ \ val\ y\ {\isacharcolon}{\isacharcolon}\ ys\ {\isacharequal}\ rev\ {\isacharparenleft}v\ {\isacharcolon}{\isacharcolon}\ va{\isacharparenright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   169
\ \ \ \ in\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   170
\ \ \ \ \ \ {\isacharparenleft}SOME\ y{\isacharcomma}\ AQueue\ {\isacharparenleft}{\isacharbrackleft}{\isacharbrackright}{\isacharcomma}\ ys{\isacharparenright}{\isacharparenright}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   171
\ \ \ \ end{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   172
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   173
fun\ enqueue\ x\ {\isacharparenleft}AQueue\ {\isacharparenleft}xs{\isacharcomma}\ ys{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ AQueue\ {\isacharparenleft}x\ {\isacharcolon}{\isacharcolon}\ xs{\isacharcomma}\ ys{\isacharparenright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   174
\isanewline
39683
f75a01ee6c41 prefer typewrite tag over raw latex environment
haftmann
parents: 39664
diff changeset
   175
end{\isacharsemicolon}\ {\isacharparenleft}{\isacharasterisk}struct\ Example{\isacharasterisk}{\isacharparenright}\isanewline%
28447
haftmann
parents:
diff changeset
   176
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   177
\isamarkuptrue%
haftmann
parents:
diff changeset
   178
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   179
\endisatagquotetypewriter
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   180
{\isafoldquotetypewriter}%
28447
haftmann
parents:
diff changeset
   181
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   182
\isadelimquotetypewriter
28447
haftmann
parents:
diff changeset
   183
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   184
\endisadelimquotetypewriter
28447
haftmann
parents:
diff changeset
   185
%
haftmann
parents:
diff changeset
   186
\begin{isamarkuptext}%
38505
2f8699695cf6 use command_def vs. command more consciously
haftmann
parents: 38460
diff changeset
   187
\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
   188
  space-separated list of constants for which code shall be generated;
2f8699695cf6 use command_def vs. command more consciously
haftmann
parents: 38460
diff changeset
   189
  anything else needed for those is added implicitly.  Then follows a
2f8699695cf6 use command_def vs. command more consciously
haftmann
parents: 38460
diff changeset
   190
  target language identifier and a freely chosen module name.  A file
2f8699695cf6 use command_def vs. command more consciously
haftmann
parents: 38460
diff changeset
   191
  name denotes the destination to store the generated code.  Note that
2f8699695cf6 use command_def vs. command more consciously
haftmann
parents: 38460
diff changeset
   192
  the semantics of the destination depends on the target language: for
38813
f50f0802ba99 updated generated files
haftmann
parents: 38505
diff changeset
   193
  \isa{SML}, \isa{OCaml} and \isa{Scala} it denotes a \emph{file},
f50f0802ba99 updated generated files
haftmann
parents: 38505
diff changeset
   194
  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
   195
  module name (with extension \isa{{\isachardot}hs}) is written:%
28447
haftmann
parents:
diff changeset
   196
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   197
\isamarkuptrue%
haftmann
parents:
diff changeset
   198
%
28564
haftmann
parents: 28447
diff changeset
   199
\isadelimquote
28447
haftmann
parents:
diff changeset
   200
%
28564
haftmann
parents: 28447
diff changeset
   201
\endisadelimquote
28447
haftmann
parents:
diff changeset
   202
%
28564
haftmann
parents: 28447
diff changeset
   203
\isatagquote
28447
haftmann
parents:
diff changeset
   204
\isacommand{export{\isacharunderscore}code}\isamarkupfalse%
haftmann
parents:
diff changeset
   205
\ empty\ dequeue\ enqueue\ \isakeyword{in}\ Haskell\isanewline
haftmann
parents:
diff changeset
   206
\ \ \isakeyword{module{\isacharunderscore}name}\ Example\ \isakeyword{file}\ {\isachardoublequoteopen}examples{\isacharslash}{\isachardoublequoteclose}%
28564
haftmann
parents: 28447
diff changeset
   207
\endisatagquote
haftmann
parents: 28447
diff changeset
   208
{\isafoldquote}%
28447
haftmann
parents:
diff changeset
   209
%
28564
haftmann
parents: 28447
diff changeset
   210
\isadelimquote
28447
haftmann
parents:
diff changeset
   211
%
28564
haftmann
parents: 28447
diff changeset
   212
\endisadelimquote
28447
haftmann
parents:
diff changeset
   213
%
haftmann
parents:
diff changeset
   214
\begin{isamarkuptext}%
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   215
\noindent This is the corresponding code:%
28447
haftmann
parents:
diff changeset
   216
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   217
\isamarkuptrue%
haftmann
parents:
diff changeset
   218
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   219
\isadelimquotetypewriter
28447
haftmann
parents:
diff changeset
   220
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   221
\endisadelimquotetypewriter
28447
haftmann
parents:
diff changeset
   222
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   223
\isatagquotetypewriter
28447
haftmann
parents:
diff changeset
   224
%
haftmann
parents:
diff changeset
   225
\begin{isamarkuptext}%
39683
f75a01ee6c41 prefer typewrite tag over raw latex environment
haftmann
parents: 39664
diff changeset
   226
module\ Example\ where\ {\isacharbraceleft}\isanewline
39664
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   227
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   228
data\ Queue\ a\ {\isacharequal}\ AQueue\ {\isacharbrackleft}a{\isacharbrackright}\ {\isacharbrackleft}a{\isacharbrackright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   229
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   230
empty\ {\isacharcolon}{\isacharcolon}\ forall\ a{\isachardot}\ Queue\ a{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   231
empty\ {\isacharequal}\ AQueue\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharbrackleft}{\isacharbrackright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   232
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   233
dequeue\ {\isacharcolon}{\isacharcolon}\ forall\ a{\isachardot}\ Queue\ a\ {\isacharminus}{\isachargreater}\ {\isacharparenleft}Maybe\ a{\isacharcomma}\ Queue\ a{\isacharparenright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   234
dequeue\ {\isacharparenleft}AQueue\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}Nothing{\isacharcomma}\ AQueue\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   235
dequeue\ {\isacharparenleft}AQueue\ xs\ {\isacharparenleft}y\ {\isacharcolon}\ ys{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}Just\ y{\isacharcomma}\ AQueue\ xs\ ys{\isacharparenright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   236
dequeue\ {\isacharparenleft}AQueue\ {\isacharparenleft}v\ {\isacharcolon}\ va{\isacharparenright}\ {\isacharbrackleft}{\isacharbrackright}{\isacharparenright}\ {\isacharequal}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   237
\ \ let\ {\isacharbraceleft}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   238
\ \ \ \ {\isacharparenleft}y\ {\isacharcolon}\ ys{\isacharparenright}\ {\isacharequal}\ reverse\ {\isacharparenleft}v\ {\isacharcolon}\ va{\isacharparenright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   239
\ \ {\isacharbraceright}\ in\ {\isacharparenleft}Just\ y{\isacharcomma}\ AQueue\ {\isacharbrackleft}{\isacharbrackright}\ ys{\isacharparenright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   240
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   241
enqueue\ {\isacharcolon}{\isacharcolon}\ forall\ a{\isachardot}\ a\ {\isacharminus}{\isachargreater}\ Queue\ a\ {\isacharminus}{\isachargreater}\ Queue\ a{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   242
enqueue\ x\ {\isacharparenleft}AQueue\ xs\ ys{\isacharparenright}\ {\isacharequal}\ AQueue\ {\isacharparenleft}x\ {\isacharcolon}\ xs{\isacharparenright}\ ys{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   243
\isanewline
39683
f75a01ee6c41 prefer typewrite tag over raw latex environment
haftmann
parents: 39664
diff changeset
   244
{\isacharbraceright}\isanewline%
28447
haftmann
parents:
diff changeset
   245
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   246
\isamarkuptrue%
haftmann
parents:
diff changeset
   247
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   248
\endisatagquotetypewriter
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   249
{\isafoldquotetypewriter}%
28447
haftmann
parents:
diff changeset
   250
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   251
\isadelimquotetypewriter
28447
haftmann
parents:
diff changeset
   252
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   253
\endisadelimquotetypewriter
28447
haftmann
parents:
diff changeset
   254
%
haftmann
parents:
diff changeset
   255
\begin{isamarkuptext}%
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   256
\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
   257
  \secref{sec:further}.%
28447
haftmann
parents:
diff changeset
   258
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   259
\isamarkuptrue%
haftmann
parents:
diff changeset
   260
%
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   261
\isamarkupsubsection{Type classes%
28447
haftmann
parents:
diff changeset
   262
}
haftmann
parents:
diff changeset
   263
\isamarkuptrue%
haftmann
parents:
diff changeset
   264
%
haftmann
parents:
diff changeset
   265
\begin{isamarkuptext}%
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   266
Code can also be generated from type classes in a Haskell-like
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   267
  manner.  For illustration here an example from abstract algebra:%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   268
\end{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   269
\isamarkuptrue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   270
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   271
\isadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   272
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   273
\endisadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   274
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   275
\isatagquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   276
\isacommand{class}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   277
\ semigroup\ {\isacharequal}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   278
\ \ \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
   279
\ \ \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
   280
\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   281
\isacommand{class}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   282
\ monoid\ {\isacharequal}\ semigroup\ {\isacharplus}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   283
\ \ \isakeyword{fixes}\ neutral\ {\isacharcolon}{\isacharcolon}\ {\isacharprime}a\ {\isacharparenleft}{\isachardoublequoteopen}{\isasymone}{\isachardoublequoteclose}{\isacharparenright}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   284
\ \ \isakeyword{assumes}\ neutl{\isacharcolon}\ {\isachardoublequoteopen}{\isasymone}\ {\isasymotimes}\ x\ {\isacharequal}\ x{\isachardoublequoteclose}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   285
\ \ \ \ \isakeyword{and}\ neutr{\isacharcolon}\ {\isachardoublequoteopen}x\ {\isasymotimes}\ {\isasymone}\ {\isacharequal}\ x{\isachardoublequoteclose}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   286
\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   287
\isacommand{instantiation}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   288
\ nat\ {\isacharcolon}{\isacharcolon}\ monoid\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   289
\isakeyword{begin}\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{primrec}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   292
\ mult{\isacharunderscore}nat\ \isakeyword{where}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   293
\ \ \ \ {\isachardoublequoteopen}{\isadigit{0}}\ {\isasymotimes}\ n\ {\isacharequal}\ {\isacharparenleft}{\isadigit{0}}{\isasymColon}nat{\isacharparenright}{\isachardoublequoteclose}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   294
\ \ {\isacharbar}\ {\isachardoublequoteopen}Suc\ m\ {\isasymotimes}\ n\ {\isacharequal}\ n\ {\isacharplus}\ m\ {\isasymotimes}\ n{\isachardoublequoteclose}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   295
\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   296
\isacommand{definition}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   297
\ neutral{\isacharunderscore}nat\ \isakeyword{where}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   298
\ \ {\isachardoublequoteopen}{\isasymone}\ {\isacharequal}\ Suc\ {\isadigit{0}}{\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{lemma}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   301
\ add{\isacharunderscore}mult{\isacharunderscore}distrib{\isacharcolon}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   302
\ \ \isakeyword{fixes}\ n\ m\ q\ {\isacharcolon}{\isacharcolon}\ nat\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   303
\ \ \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
   304
\ \ \isacommand{by}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   305
\ {\isacharparenleft}induct\ n{\isacharparenright}\ simp{\isacharunderscore}all\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   306
\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   307
\isacommand{instance}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   308
\ \isacommand{proof}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   309
\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   310
\ \ \isacommand{fix}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   311
\ m\ n\ q\ {\isacharcolon}{\isacharcolon}\ nat\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   312
\ \ \isacommand{show}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   313
\ {\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
   314
\ \ \ \ \isacommand{by}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   315
\ {\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
   316
\ \ \isacommand{show}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   317
\ {\isachardoublequoteopen}{\isasymone}\ {\isasymotimes}\ n\ {\isacharequal}\ n{\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}simp\ add{\isacharcolon}\ neutral{\isacharunderscore}nat{\isacharunderscore}def{\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}m\ {\isasymotimes}\ {\isasymone}\ {\isacharequal}\ m{\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}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
   324
\isacommand{qed}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   325
\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   326
\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   327
\isacommand{end}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   328
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   329
\endisatagquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   330
{\isafoldquote}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   331
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   332
\isadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   333
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   334
\endisadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   335
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   336
\begin{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   337
\noindent We define the natural operation of the natural numbers
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   338
  on monoids:%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   339
\end{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   340
\isamarkuptrue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   341
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   342
\isadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   343
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   344
\endisadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   345
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   346
\isatagquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   347
\isacommand{primrec}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   348
\ {\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
   349
\ \ \ \ {\isachardoublequoteopen}pow\ {\isadigit{0}}\ a\ {\isacharequal}\ {\isasymone}{\isachardoublequoteclose}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   350
\ \ {\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
   351
\endisatagquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   352
{\isafoldquote}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   353
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   354
\isadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   355
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   356
\endisadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   357
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   358
\begin{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   359
\noindent This we use to define the discrete exponentiation
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   360
  function:%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   361
\end{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   362
\isamarkuptrue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   363
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   364
\isadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   365
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   366
\endisadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   367
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   368
\isatagquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   369
\isacommand{definition}\isamarkupfalse%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   370
\ bexp\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymRightarrow}\ nat{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   371
\ \ {\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
   372
\endisatagquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   373
{\isafoldquote}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   374
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   375
\isadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   376
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   377
\endisadelimquote
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   378
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   379
\begin{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   380
\noindent The corresponding code in Haskell uses that language's
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   381
  native classes:%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   382
\end{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   383
\isamarkuptrue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   384
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   385
\isadelimquotetypewriter
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   386
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   387
\endisadelimquotetypewriter
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   388
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   389
\isatagquotetypewriter
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   390
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   391
\begin{isamarkuptext}%
39683
f75a01ee6c41 prefer typewrite tag over raw latex environment
haftmann
parents: 39664
diff changeset
   392
module\ Example\ where\ {\isacharbraceleft}\isanewline
39664
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   393
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   394
data\ Nat\ {\isacharequal}\ Zero{\isacharunderscore}nat\ {\isacharbar}\ Suc\ Nat{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   395
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   396
plus{\isacharunderscore}nat\ {\isacharcolon}{\isacharcolon}\ Nat\ {\isacharminus}{\isachargreater}\ Nat\ {\isacharminus}{\isachargreater}\ Nat{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   397
plus{\isacharunderscore}nat\ {\isacharparenleft}Suc\ m{\isacharparenright}\ n\ {\isacharequal}\ plus{\isacharunderscore}nat\ m\ {\isacharparenleft}Suc\ n{\isacharparenright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   398
plus{\isacharunderscore}nat\ Zero{\isacharunderscore}nat\ n\ {\isacharequal}\ n{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   399
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   400
class\ Semigroup\ a\ where\ {\isacharbraceleft}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   401
\ \ mult\ {\isacharcolon}{\isacharcolon}\ a\ {\isacharminus}{\isachargreater}\ a\ {\isacharminus}{\isachargreater}\ a{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   402
{\isacharbraceright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   403
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   404
class\ {\isacharparenleft}Semigroup\ a{\isacharparenright}\ {\isacharequal}{\isachargreater}\ Monoid\ a\ where\ {\isacharbraceleft}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   405
\ \ neutral\ {\isacharcolon}{\isacharcolon}\ a{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   406
{\isacharbraceright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   407
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   408
pow\ {\isacharcolon}{\isacharcolon}\ forall\ a{\isachardot}\ {\isacharparenleft}Monoid\ a{\isacharparenright}\ {\isacharequal}{\isachargreater}\ Nat\ {\isacharminus}{\isachargreater}\ a\ {\isacharminus}{\isachargreater}\ a{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   409
pow\ Zero{\isacharunderscore}nat\ a\ {\isacharequal}\ neutral{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   410
pow\ {\isacharparenleft}Suc\ n{\isacharparenright}\ a\ {\isacharequal}\ mult\ a\ {\isacharparenleft}pow\ n\ a{\isacharparenright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   411
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   412
mult{\isacharunderscore}nat\ {\isacharcolon}{\isacharcolon}\ Nat\ {\isacharminus}{\isachargreater}\ Nat\ {\isacharminus}{\isachargreater}\ Nat{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   413
mult{\isacharunderscore}nat\ Zero{\isacharunderscore}nat\ n\ {\isacharequal}\ Zero{\isacharunderscore}nat{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   414
mult{\isacharunderscore}nat\ {\isacharparenleft}Suc\ m{\isacharparenright}\ n\ {\isacharequal}\ plus{\isacharunderscore}nat\ n\ {\isacharparenleft}mult{\isacharunderscore}nat\ m\ n{\isacharparenright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   415
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   416
instance\ Semigroup\ Nat\ where\ {\isacharbraceleft}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   417
\ \ mult\ {\isacharequal}\ mult{\isacharunderscore}nat{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   418
{\isacharbraceright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   419
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   420
neutral{\isacharunderscore}nat\ {\isacharcolon}{\isacharcolon}\ Nat{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   421
neutral{\isacharunderscore}nat\ {\isacharequal}\ Suc\ Zero{\isacharunderscore}nat{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   422
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   423
instance\ Monoid\ Nat\ where\ {\isacharbraceleft}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   424
\ \ neutral\ {\isacharequal}\ neutral{\isacharunderscore}nat{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   425
{\isacharbraceright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   426
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   427
bexp\ {\isacharcolon}{\isacharcolon}\ Nat\ {\isacharminus}{\isachargreater}\ Nat{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   428
bexp\ n\ {\isacharequal}\ pow\ n\ {\isacharparenleft}Suc\ {\isacharparenleft}Suc\ Zero{\isacharunderscore}nat{\isacharparenright}{\isacharparenright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   429
\isanewline
39683
f75a01ee6c41 prefer typewrite tag over raw latex environment
haftmann
parents: 39664
diff changeset
   430
{\isacharbraceright}\isanewline%
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   431
\end{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   432
\isamarkuptrue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   433
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   434
\endisatagquotetypewriter
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   435
{\isafoldquotetypewriter}%
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   436
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   437
\isadelimquotetypewriter
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   438
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   439
\endisadelimquotetypewriter
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   440
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   441
\begin{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   442
\noindent This is a convenient place to show how explicit dictionary
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   443
  construction manifests in generated code -- the same example in
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   444
  \isa{SML}:%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   445
\end{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   446
\isamarkuptrue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   447
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   448
\isadelimquotetypewriter
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   449
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   450
\endisadelimquotetypewriter
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   451
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   452
\isatagquotetypewriter
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   453
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   454
\begin{isamarkuptext}%
39683
f75a01ee6c41 prefer typewrite tag over raw latex environment
haftmann
parents: 39664
diff changeset
   455
structure\ Example\ {\isacharcolon}\ sig\isanewline
39664
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   456
\ \ datatype\ nat\ {\isacharequal}\ Zero{\isacharunderscore}nat\ {\isacharbar}\ Suc\ of\ nat\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   457
\ \ val\ plus{\isacharunderscore}nat\ {\isacharcolon}\ nat\ {\isacharminus}{\isachargreater}\ nat\ {\isacharminus}{\isachargreater}\ nat\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   458
\ \ type\ {\isacharprime}a\ semigroup\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   459
\ \ val\ mult\ {\isacharcolon}\ {\isacharprime}a\ semigroup\ {\isacharminus}{\isachargreater}\ {\isacharprime}a\ {\isacharminus}{\isachargreater}\ {\isacharprime}a\ {\isacharminus}{\isachargreater}\ {\isacharprime}a\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   460
\ \ type\ {\isacharprime}a\ monoid\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   461
\ \ val\ semigroup{\isacharunderscore}monoid\ {\isacharcolon}\ {\isacharprime}a\ monoid\ {\isacharminus}{\isachargreater}\ {\isacharprime}a\ semigroup\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   462
\ \ val\ neutral\ {\isacharcolon}\ {\isacharprime}a\ monoid\ {\isacharminus}{\isachargreater}\ {\isacharprime}a\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   463
\ \ val\ pow\ {\isacharcolon}\ {\isacharprime}a\ monoid\ {\isacharminus}{\isachargreater}\ nat\ {\isacharminus}{\isachargreater}\ {\isacharprime}a\ {\isacharminus}{\isachargreater}\ {\isacharprime}a\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   464
\ \ val\ mult{\isacharunderscore}nat\ {\isacharcolon}\ nat\ {\isacharminus}{\isachargreater}\ nat\ {\isacharminus}{\isachargreater}\ nat\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   465
\ \ val\ semigroup{\isacharunderscore}nat\ {\isacharcolon}\ nat\ semigroup\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   466
\ \ val\ neutral{\isacharunderscore}nat\ {\isacharcolon}\ nat\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   467
\ \ val\ monoid{\isacharunderscore}nat\ {\isacharcolon}\ nat\ monoid\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   468
\ \ val\ bexp\ {\isacharcolon}\ nat\ {\isacharminus}{\isachargreater}\ nat\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   469
end\ {\isacharequal}\ struct\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   470
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   471
datatype\ nat\ {\isacharequal}\ Zero{\isacharunderscore}nat\ {\isacharbar}\ Suc\ of\ nat{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   472
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   473
fun\ plus{\isacharunderscore}nat\ {\isacharparenleft}Suc\ m{\isacharparenright}\ n\ {\isacharequal}\ plus{\isacharunderscore}nat\ m\ {\isacharparenleft}Suc\ n{\isacharparenright}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   474
\ \ {\isacharbar}\ plus{\isacharunderscore}nat\ Zero{\isacharunderscore}nat\ n\ {\isacharequal}\ n{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   475
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   476
type\ {\isacharprime}a\ semigroup\ {\isacharequal}\ {\isacharbraceleft}mult\ {\isacharcolon}\ {\isacharprime}a\ {\isacharminus}{\isachargreater}\ {\isacharprime}a\ {\isacharminus}{\isachargreater}\ {\isacharprime}a{\isacharbraceright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   477
val\ mult\ {\isacharequal}\ {\isacharhash}mult\ {\isacharcolon}\ {\isacharprime}a\ semigroup\ {\isacharminus}{\isachargreater}\ {\isacharprime}a\ {\isacharminus}{\isachargreater}\ {\isacharprime}a\ {\isacharminus}{\isachargreater}\ {\isacharprime}a{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   478
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   479
type\ {\isacharprime}a\ monoid\ {\isacharequal}\ {\isacharbraceleft}semigroup{\isacharunderscore}monoid\ {\isacharcolon}\ {\isacharprime}a\ semigroup{\isacharcomma}\ neutral\ {\isacharcolon}\ {\isacharprime}a{\isacharbraceright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   480
val\ semigroup{\isacharunderscore}monoid\ {\isacharequal}\ {\isacharhash}semigroup{\isacharunderscore}monoid\ {\isacharcolon}\ {\isacharprime}a\ monoid\ {\isacharminus}{\isachargreater}\ {\isacharprime}a\ semigroup{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   481
val\ neutral\ {\isacharequal}\ {\isacharhash}neutral\ {\isacharcolon}\ {\isacharprime}a\ monoid\ {\isacharminus}{\isachargreater}\ {\isacharprime}a{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   482
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   483
fun\ pow\ A{\isacharunderscore}\ Zero{\isacharunderscore}nat\ a\ {\isacharequal}\ neutral\ A{\isacharunderscore}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   484
\ \ {\isacharbar}\ pow\ A{\isacharunderscore}\ {\isacharparenleft}Suc\ n{\isacharparenright}\ a\ {\isacharequal}\ mult\ {\isacharparenleft}semigroup{\isacharunderscore}monoid\ A{\isacharunderscore}{\isacharparenright}\ a\ {\isacharparenleft}pow\ A{\isacharunderscore}\ n\ a{\isacharparenright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   485
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   486
fun\ mult{\isacharunderscore}nat\ Zero{\isacharunderscore}nat\ n\ {\isacharequal}\ Zero{\isacharunderscore}nat\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   487
\ \ {\isacharbar}\ mult{\isacharunderscore}nat\ {\isacharparenleft}Suc\ m{\isacharparenright}\ n\ {\isacharequal}\ plus{\isacharunderscore}nat\ n\ {\isacharparenleft}mult{\isacharunderscore}nat\ m\ n{\isacharparenright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   488
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   489
val\ semigroup{\isacharunderscore}nat\ {\isacharequal}\ {\isacharbraceleft}mult\ {\isacharequal}\ mult{\isacharunderscore}nat{\isacharbraceright}\ {\isacharcolon}\ nat\ semigroup{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   490
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   491
val\ neutral{\isacharunderscore}nat\ {\isacharcolon}\ nat\ {\isacharequal}\ Suc\ Zero{\isacharunderscore}nat{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   492
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   493
val\ monoid{\isacharunderscore}nat\ {\isacharequal}\ {\isacharbraceleft}semigroup{\isacharunderscore}monoid\ {\isacharequal}\ semigroup{\isacharunderscore}nat{\isacharcomma}\ neutral\ {\isacharequal}\ neutral{\isacharunderscore}nat{\isacharbraceright}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   494
\ \ {\isacharcolon}\ nat\ monoid{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   495
\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   496
fun\ bexp\ n\ {\isacharequal}\ pow\ monoid{\isacharunderscore}nat\ n\ {\isacharparenleft}Suc\ {\isacharparenleft}Suc\ Zero{\isacharunderscore}nat{\isacharparenright}{\isacharparenright}{\isacharsemicolon}\isanewline
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 39210
diff changeset
   497
\isanewline
39683
f75a01ee6c41 prefer typewrite tag over raw latex environment
haftmann
parents: 39664
diff changeset
   498
end{\isacharsemicolon}\ {\isacharparenleft}{\isacharasterisk}struct\ Example{\isacharasterisk}{\isacharparenright}\isanewline%
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   499
\end{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   500
\isamarkuptrue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   501
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   502
\endisatagquotetypewriter
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   503
{\isafoldquotetypewriter}%
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   504
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   505
\isadelimquotetypewriter
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   506
%
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   507
\endisadelimquotetypewriter
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   508
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   509
\begin{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   510
\noindent Note the parameters with trailing underscore (\verb|A_|), which are the dictionary parameters.%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   511
\end{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   512
\isamarkuptrue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   513
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   514
\isamarkupsubsection{How to continue from here%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   515
}
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   516
\isamarkuptrue%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   517
%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   518
\begin{isamarkuptext}%
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   519
What you have seen so far should be already enough in a lot of
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   520
  cases.  If you are content with this, you can quit reading here.
28447
haftmann
parents:
diff changeset
   521
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   522
  Anyway, to understand situations where problems occur or to increase
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   523
  the scope of code generation beyond default, it is necessary to gain
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   524
  some understanding how the code generator actually works:
28447
haftmann
parents:
diff changeset
   525
haftmann
parents:
diff changeset
   526
  \begin{itemize}
haftmann
parents:
diff changeset
   527
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   528
    \item The foundations of the code generator are described in
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   529
      \secref{sec:foundations}.
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   530
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   531
    \item In particular \secref{sec:utterly_wrong} gives hints how to
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   532
      debug situations where code generation does not succeed as
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   533
      expected.
28447
haftmann
parents:
diff changeset
   534
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   535
    \item The scope and quality of generated code can be increased
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   536
      dramatically by applying refinement techniques, which are
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   537
      introduced in \secref{sec:refinement}.
28447
haftmann
parents:
diff changeset
   538
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   539
    \item Inductive predicates can be turned executable using an
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   540
      extension of the code generator \secref{sec:inductive}.
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   541
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   542
    \item You may want to skim over the more technical sections
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   543
      \secref{sec:adaptation} and \secref{sec:further}.
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   544
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   545
    \item For exhaustive syntax diagrams etc. you should visit the
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   546
      Isabelle/Isar Reference Manual \cite{isabelle-isar-ref}.
28447
haftmann
parents:
diff changeset
   547
haftmann
parents:
diff changeset
   548
  \end{itemize}
haftmann
parents:
diff changeset
   549
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   550
  \bigskip
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   551
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   552
  \begin{center}\fbox{\fbox{\begin{minipage}{8cm}
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   553
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   554
    \begin{center}\textit{Happy proving, happy hacking!}\end{center}
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   555
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   556
  \end{minipage}}}\end{center}
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   557
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   558
  \begin{warn}
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   559
    There is also a more ancient code generator in Isabelle by Stefan
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   560
    Berghofer \cite{Berghofer-Nipkow:2002}.  Although its
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   561
    functionality is covered by the code generator presented here, it
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   562
    will sometimes show up as an artifact.  In case of ambiguity, we
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   563
    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
   564
  \end{warn}%
28447
haftmann
parents:
diff changeset
   565
\end{isamarkuptext}%
haftmann
parents:
diff changeset
   566
\isamarkuptrue%
haftmann
parents:
diff changeset
   567
%
haftmann
parents:
diff changeset
   568
\isadelimtheory
haftmann
parents:
diff changeset
   569
%
haftmann
parents:
diff changeset
   570
\endisadelimtheory
haftmann
parents:
diff changeset
   571
%
haftmann
parents:
diff changeset
   572
\isatagtheory
haftmann
parents:
diff changeset
   573
\isacommand{end}\isamarkupfalse%
haftmann
parents:
diff changeset
   574
%
haftmann
parents:
diff changeset
   575
\endisatagtheory
haftmann
parents:
diff changeset
   576
{\isafoldtheory}%
haftmann
parents:
diff changeset
   577
%
haftmann
parents:
diff changeset
   578
\isadelimtheory
haftmann
parents:
diff changeset
   579
%
haftmann
parents:
diff changeset
   580
\endisadelimtheory
haftmann
parents:
diff changeset
   581
\isanewline
haftmann
parents:
diff changeset
   582
\end{isabellebody}%
haftmann
parents:
diff changeset
   583
%%% Local Variables:
haftmann
parents:
diff changeset
   584
%%% mode: latex
haftmann
parents:
diff changeset
   585
%%% TeX-master: "root"
haftmann
parents:
diff changeset
   586
%%% End: