src/Doc/Codegen/Introduction.thy
author wenzelm
Fri, 09 May 2014 22:14:06 +0200
changeset 56933 b47193851dc6
parent 48985 5386df44a037
child 58305 57752a91eec4
permissions -rw-r--r--
more markup;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28213
b52f9205a02d New outline for codegen tutorial -- draft
haftmann
parents:
diff changeset
     1
theory Introduction
b52f9205a02d New outline for codegen tutorial -- draft
haftmann
parents:
diff changeset
     2
imports Setup
b52f9205a02d New outline for codegen tutorial -- draft
haftmann
parents:
diff changeset
     3
begin
b52f9205a02d New outline for codegen tutorial -- draft
haftmann
parents:
diff changeset
     4
38405
7935b334893e sketch of new outline
haftmann
parents: 38402
diff changeset
     5
section {* Introduction *}
7935b334893e sketch of new outline
haftmann
parents: 38402
diff changeset
     6
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
     7
text {*
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
     8
  This tutorial introduces the code generator facilities of @{text
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
     9
  "Isabelle/HOL"}.  It allows to turn (a certain class of) HOL
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
    10
  specifications into corresponding executable code in the programming
38814
4d575fbfc920 official support for Scala
haftmann
parents: 38505
diff changeset
    11
  languages @{text SML} \cite{SML}, @{text OCaml} \cite{OCaml},
4d575fbfc920 official support for Scala
haftmann
parents: 38505
diff changeset
    12
  @{text Haskell} \cite{haskell-revised-report} and @{text Scala}
4d575fbfc920 official support for Scala
haftmann
parents: 38505
diff changeset
    13
  \cite{scala-overview-tech-report}.
38405
7935b334893e sketch of new outline
haftmann
parents: 38402
diff changeset
    14
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
    15
  To profit from this tutorial, some familiarity and experience with
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
    16
  @{theory HOL} \cite{isa-tutorial} and its basic theories is assumed.
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
    17
*}
38405
7935b334893e sketch of new outline
haftmann
parents: 38402
diff changeset
    18
7935b334893e sketch of new outline
haftmann
parents: 38402
diff changeset
    19
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
    20
subsection {* Code generation principle: shallow embedding \label{sec:principle} *}
28213
b52f9205a02d New outline for codegen tutorial -- draft
haftmann
parents:
diff changeset
    21
b52f9205a02d New outline for codegen tutorial -- draft
haftmann
parents:
diff changeset
    22
text {*
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
    23
  The key concept for understanding Isabelle's code generation is
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
    24
  \emph{shallow embedding}: logical entities like constants, types and
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
    25
  classes are identified with corresponding entities in the target
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
    26
  language.  In particular, the carrier of a generated program's
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
    27
  semantics are \emph{equational theorems} from the logic.  If we view
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
    28
  a generated program as an implementation of a higher-order rewrite
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
    29
  system, then every rewrite step performed by the program can be
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
    30
  simulated in the logic, which guarantees partial correctness
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
    31
  \cite{Haftmann-Nipkow:2010:code}.
28213
b52f9205a02d New outline for codegen tutorial -- draft
haftmann
parents:
diff changeset
    32
*}
b52f9205a02d New outline for codegen tutorial -- draft
haftmann
parents:
diff changeset
    33
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
    34
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
    35
subsection {* A quick start with the Isabelle/HOL toolbox \label{sec:queue_example} *}
28419
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
    36
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
    37
text {*
38505
2f8699695cf6 use command_def vs. command more consciously
haftmann
parents: 38437
diff changeset
    38
  In a HOL theory, the @{command_def datatype} and @{command_def
2f8699695cf6 use command_def vs. command more consciously
haftmann
parents: 38437
diff changeset
    39
  definition}/@{command_def primrec}/@{command_def fun} declarations
2f8699695cf6 use command_def vs. command more consciously
haftmann
parents: 38437
diff changeset
    40
  form the core of a functional programming language.  By default
2f8699695cf6 use command_def vs. command more consciously
haftmann
parents: 38437
diff changeset
    41
  equational theorems stemming from those are used for generated code,
2f8699695cf6 use command_def vs. command more consciously
haftmann
parents: 38437
diff changeset
    42
  therefore \qt{naive} code generation can proceed without further
2f8699695cf6 use command_def vs. command more consciously
haftmann
parents: 38437
diff changeset
    43
  ado.
28419
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
    44
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
    45
  For example, here a simple \qt{implementation} of amortised queues:
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
    46
*}
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
    47
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
    48
datatype %quote 'a queue = AQueue "'a list" "'a list"
28419
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
    49
28564
haftmann
parents: 28447
diff changeset
    50
definition %quote empty :: "'a queue" where
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
    51
  "empty = AQueue [] []"
28419
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
    52
28564
haftmann
parents: 28447
diff changeset
    53
primrec %quote enqueue :: "'a \<Rightarrow> 'a queue \<Rightarrow> 'a queue" where
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
    54
  "enqueue x (AQueue xs ys) = AQueue (x # xs) ys"
28419
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
    55
28564
haftmann
parents: 28447
diff changeset
    56
fun %quote dequeue :: "'a queue \<Rightarrow> 'a option \<times> 'a queue" where
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
    57
    "dequeue (AQueue [] []) = (None, AQueue [] [])"
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
    58
  | "dequeue (AQueue xs (y # ys)) = (Some y, AQueue xs ys)"
6df726203e39 proper datatype abstraction example
haftmann
parents: 29560
diff changeset
    59
  | "dequeue (AQueue xs []) =
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
    60
      (case rev xs of y # ys \<Rightarrow> (Some y, AQueue [] ys))" (*<*)
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
    61
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
    62
lemma %invisible dequeue_nonempty_Nil [simp]:
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
    63
  "xs \<noteq> [] \<Longrightarrow> dequeue (AQueue xs []) = (case rev xs of y # ys \<Rightarrow> (Some y, AQueue [] ys))"
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
    64
  by (cases xs) (simp_all split: list.splits) (*>*)
28419
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
    65
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
    66
text {* \noindent Then we can generate code e.g.~for @{text SML} as follows: *}
28213
b52f9205a02d New outline for codegen tutorial -- draft
haftmann
parents:
diff changeset
    67
28564
haftmann
parents: 28447
diff changeset
    68
export_code %quote empty dequeue enqueue in SML
28447
haftmann
parents: 28428
diff changeset
    69
  module_name Example file "examples/example.ML"
28419
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
    70
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
    71
text {* \noindent resulting in the following code: *}
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
    72
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
    73
text %quotetypewriter {*
39683
f75a01ee6c41 prefer typewrite tag over raw latex environment
haftmann
parents: 39664
diff changeset
    74
  @{code_stmts empty enqueue dequeue (SML)}
39664
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 38814
diff changeset
    75
*}
28419
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
    76
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
    77
text {*
38505
2f8699695cf6 use command_def vs. command more consciously
haftmann
parents: 38437
diff changeset
    78
  \noindent The @{command_def export_code} command takes a
2f8699695cf6 use command_def vs. command more consciously
haftmann
parents: 38437
diff changeset
    79
  space-separated list of constants for which code shall be generated;
2f8699695cf6 use command_def vs. command more consciously
haftmann
parents: 38437
diff changeset
    80
  anything else needed for those is added implicitly.  Then follows a
2f8699695cf6 use command_def vs. command more consciously
haftmann
parents: 38437
diff changeset
    81
  target language identifier and a freely chosen module name.  A file
2f8699695cf6 use command_def vs. command more consciously
haftmann
parents: 38437
diff changeset
    82
  name denotes the destination to store the generated code.  Note that
2f8699695cf6 use command_def vs. command more consciously
haftmann
parents: 38437
diff changeset
    83
  the semantics of the destination depends on the target language: for
38814
4d575fbfc920 official support for Scala
haftmann
parents: 38505
diff changeset
    84
  @{text SML}, @{text OCaml} and @{text Scala} it denotes a \emph{file},
4d575fbfc920 official support for Scala
haftmann
parents: 38505
diff changeset
    85
  for @{text Haskell} it denotes a \emph{directory} where a file named as the
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
    86
  module name (with extension @{text ".hs"}) is written:
28419
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
    87
*}
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
    88
28564
haftmann
parents: 28447
diff changeset
    89
export_code %quote empty dequeue enqueue in Haskell
28447
haftmann
parents: 28428
diff changeset
    90
  module_name Example file "examples/"
28419
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
    91
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
    92
text {*
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
    93
  \noindent This is the corresponding code:
28419
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
    94
*}
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
    95
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
    96
text %quotetypewriter {*
39683
f75a01ee6c41 prefer typewrite tag over raw latex environment
haftmann
parents: 39664
diff changeset
    97
  @{code_stmts empty enqueue dequeue (Haskell)}
39664
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 38814
diff changeset
    98
*}
28419
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
    99
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
   100
text {*
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   101
  \noindent For more details about @{command export_code} see
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   102
  \secref{sec:further}.
28419
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
   103
*}
28213
b52f9205a02d New outline for codegen tutorial -- draft
haftmann
parents:
diff changeset
   104
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   105
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   106
subsection {* Type classes *}
38402
58fc3a3af71f added stub "If something utterly fails"
haftmann
parents: 34155
diff changeset
   107
58fc3a3af71f added stub "If something utterly fails"
haftmann
parents: 34155
diff changeset
   108
text {*
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   109
  Code can also be generated from type classes in a Haskell-like
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   110
  manner.  For illustration here an example from abstract algebra:
38402
58fc3a3af71f added stub "If something utterly fails"
haftmann
parents: 34155
diff changeset
   111
*}
58fc3a3af71f added stub "If something utterly fails"
haftmann
parents: 34155
diff changeset
   112
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   113
class %quote semigroup =
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   114
  fixes mult :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<otimes>" 70)
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   115
  assumes assoc: "(x \<otimes> y) \<otimes> z = x \<otimes> (y \<otimes> z)"
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   116
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   117
class %quote monoid = semigroup +
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   118
  fixes neutral :: 'a ("\<one>")
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   119
  assumes neutl: "\<one> \<otimes> x = x"
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   120
    and neutr: "x \<otimes> \<one> = x"
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   121
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   122
instantiation %quote nat :: monoid
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   123
begin
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   124
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   125
primrec %quote mult_nat where
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   126
    "0 \<otimes> n = (0\<Colon>nat)"
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   127
  | "Suc m \<otimes> n = n + m \<otimes> n"
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   128
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   129
definition %quote neutral_nat where
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   130
  "\<one> = Suc 0"
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   131
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   132
lemma %quote add_mult_distrib:
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   133
  fixes n m q :: nat
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   134
  shows "(n + m) \<otimes> q = n \<otimes> q + m \<otimes> q"
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   135
  by (induct n) simp_all
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   136
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   137
instance %quote proof
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   138
  fix m n q :: nat
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   139
  show "m \<otimes> n \<otimes> q = m \<otimes> (n \<otimes> q)"
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   140
    by (induct m) (simp_all add: add_mult_distrib)
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   141
  show "\<one> \<otimes> n = n"
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   142
    by (simp add: neutral_nat_def)
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   143
  show "m \<otimes> \<one> = m"
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   144
    by (induct m) (simp_all add: neutral_nat_def)
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   145
qed
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   146
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   147
end %quote
28213
b52f9205a02d New outline for codegen tutorial -- draft
haftmann
parents:
diff changeset
   148
28419
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
   149
text {*
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   150
  \noindent We define the natural operation of the natural numbers
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   151
  on monoids:
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   152
*}
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   153
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   154
primrec %quote (in monoid) pow :: "nat \<Rightarrow> 'a \<Rightarrow> 'a" where
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   155
    "pow 0 a = \<one>"
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   156
  | "pow (Suc n) a = a \<otimes> pow n a"
28419
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
   157
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   158
text {*
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   159
  \noindent This we use to define the discrete exponentiation
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   160
  function:
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   161
*}
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   162
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   163
definition %quote bexp :: "nat \<Rightarrow> nat" where
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   164
  "bexp n = pow n (Suc (Suc 0))"
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   165
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   166
text {*
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   167
  \noindent The corresponding code in Haskell uses that language's
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   168
  native classes:
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   169
*}
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   170
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   171
text %quotetypewriter {*
39683
f75a01ee6c41 prefer typewrite tag over raw latex environment
haftmann
parents: 39664
diff changeset
   172
  @{code_stmts bexp (Haskell)}
39664
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 38814
diff changeset
   173
*}
28419
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
   174
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   175
text {*
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   176
  \noindent This is a convenient place to show how explicit dictionary
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   177
  construction manifests in generated code -- the same example in
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   178
  @{text SML}:
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   179
*}
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   180
39745
3aa2bc9c5478 combine quote and typewriter/tt tag
haftmann
parents: 39683
diff changeset
   181
text %quotetypewriter {*
39683
f75a01ee6c41 prefer typewrite tag over raw latex environment
haftmann
parents: 39664
diff changeset
   182
  @{code_stmts bexp (SML)}
39664
0afaf89ab591 more canonical type setting of type writer code examples
haftmann
parents: 38814
diff changeset
   183
*}
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   184
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   185
text {*
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   186
  \noindent Note the parameters with trailing underscore (@{verbatim
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   187
  "A_"}), which are the dictionary parameters.
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   188
*}
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   189
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   190
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   191
subsection {* How to continue from here *}
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   192
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   193
text {*
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   194
  What you have seen so far should be already enough in a lot of
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   195
  cases.  If you are content with this, you can quit reading here.
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   196
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   197
  Anyway, to understand situations where problems occur or to increase
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   198
  the scope of code generation beyond default, it is necessary to gain
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   199
  some understanding how the code generator actually works:
28419
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
   200
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
   201
  \begin{itemize}
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
   202
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   203
    \item The foundations of the code generator are described in
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   204
      \secref{sec:foundations}.
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   205
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   206
    \item In particular \secref{sec:utterly_wrong} gives hints how to
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   207
      debug situations where code generation does not succeed as
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   208
      expected.
28419
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
   209
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   210
    \item The scope and quality of generated code can be increased
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   211
      dramatically by applying refinement techniques, which are
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   212
      introduced in \secref{sec:refinement}.
28419
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
   213
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   214
    \item Inductive predicates can be turned executable using an
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   215
      extension of the code generator \secref{sec:inductive}.
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   216
40753
5288144b4358 added evaluation section
haftmann
parents: 39745
diff changeset
   217
    \item If you want to utilize code generation to obtain fast
5288144b4358 added evaluation section
haftmann
parents: 39745
diff changeset
   218
      evaluators e.g.~for decision procedures, have a look at
5288144b4358 added evaluation section
haftmann
parents: 39745
diff changeset
   219
      \secref{sec:evaluation}.
5288144b4358 added evaluation section
haftmann
parents: 39745
diff changeset
   220
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   221
    \item You may want to skim over the more technical sections
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   222
      \secref{sec:adaptation} and \secref{sec:further}.
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   223
42096
9f6652122963 added subsection on Scala specialities
haftmann
parents: 40753
diff changeset
   224
    \item The target language Scala \cite{scala-overview-tech-report}
9f6652122963 added subsection on Scala specialities
haftmann
parents: 40753
diff changeset
   225
      comes with some specialities discussed in \secref{sec:scala}.
9f6652122963 added subsection on Scala specialities
haftmann
parents: 40753
diff changeset
   226
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   227
    \item For exhaustive syntax diagrams etc. you should visit the
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   228
      Isabelle/Isar Reference Manual \cite{isabelle-isar-ref}.
28419
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
   229
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
   230
  \end{itemize}
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
   231
38437
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   232
  \bigskip
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   233
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   234
  \begin{center}\fbox{\fbox{\begin{minipage}{8cm}
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   235
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   236
    \begin{center}\textit{Happy proving, happy hacking!}\end{center}
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   237
ffb1c5bf0425 adaptation to new outline
haftmann
parents: 38405
diff changeset
   238
  \end{minipage}}}\end{center}
28419
f65e8b318581 re-canibalised manual
haftmann
parents: 28213
diff changeset
   239
*}
28213
b52f9205a02d New outline for codegen tutorial -- draft
haftmann
parents:
diff changeset
   240
b52f9205a02d New outline for codegen tutorial -- draft
haftmann
parents:
diff changeset
   241
end
46522
2b1e87b3967f tuned whitespace
haftmann
parents: 45211
diff changeset
   242