src/Doc/Codegen/Introduction.thy
changeset 69505 cc2d676d5395
parent 69422 472af2d7835d
child 69597 ff784d5a5bfb
equal deleted inserted replaced
69504:bda7527ccf05 69505:cc2d676d5395
     7 \<close> (*>*)
     7 \<close> (*>*)
     8 
     8 
     9 section \<open>Introduction\<close>
     9 section \<open>Introduction\<close>
    10 
    10 
    11 text \<open>
    11 text \<open>
    12   This tutorial introduces the code generator facilities of @{text
    12   This tutorial introduces the code generator facilities of \<open>Isabelle/HOL\<close>.  It allows to turn (a certain class of) HOL
    13   "Isabelle/HOL"}.  It allows to turn (a certain class of) HOL
       
    14   specifications into corresponding executable code in the programming
    13   specifications into corresponding executable code in the programming
    15   languages @{text SML} @{cite SML}, @{text OCaml} @{cite OCaml},
    14   languages \<open>SML\<close> @{cite SML}, \<open>OCaml\<close> @{cite OCaml},
    16   @{text Haskell} @{cite "haskell-revised-report"} and @{text Scala}
    15   \<open>Haskell\<close> @{cite "haskell-revised-report"} and \<open>Scala\<close>
    17   @{cite "scala-overview-tech-report"}.
    16   @{cite "scala-overview-tech-report"}.
    18 
    17 
    19   To profit from this tutorial, some familiarity and experience with
    18   To profit from this tutorial, some familiarity and experience with
    20   Isabelle/HOL @{cite "isa-tutorial"} and its basic theories is assumed.
    19   Isabelle/HOL @{cite "isa-tutorial"} and its basic theories is assumed.
    21 \<close>
    20 \<close>
    65 
    64 
    66 lemma %invisible dequeue_nonempty_Nil [simp]:
    65 lemma %invisible dequeue_nonempty_Nil [simp]:
    67   "xs \<noteq> [] \<Longrightarrow> dequeue (AQueue xs []) = (case rev xs of y # ys \<Rightarrow> (Some y, AQueue [] ys))"
    66   "xs \<noteq> [] \<Longrightarrow> dequeue (AQueue xs []) = (case rev xs of y # ys \<Rightarrow> (Some y, AQueue [] ys))"
    68   by (cases xs) (simp_all split: list.splits) (*>*)
    67   by (cases xs) (simp_all split: list.splits) (*>*)
    69 
    68 
    70 text \<open>\noindent Then we can generate code e.g.~for @{text SML} as follows:\<close>
    69 text \<open>\noindent Then we can generate code e.g.~for \<open>SML\<close> as follows:\<close>
    71 
    70 
    72 export_code %quote empty dequeue enqueue in SML
    71 export_code %quote empty dequeue enqueue in SML
    73   module_name Example file "$ISABELLE_TMP/example.ML"
    72   module_name Example file "$ISABELLE_TMP/example.ML"
    74 
    73 
    75 text \<open>\noindent resulting in the following code:\<close>
    74 text \<open>\noindent resulting in the following code:\<close>
    83   space-separated list of constants for which code shall be generated;
    82   space-separated list of constants for which code shall be generated;
    84   anything else needed for those is added implicitly.  Then follows a
    83   anything else needed for those is added implicitly.  Then follows a
    85   target language identifier and a freely chosen module name.  A file
    84   target language identifier and a freely chosen module name.  A file
    86   name denotes the destination to store the generated code.  Note that
    85   name denotes the destination to store the generated code.  Note that
    87   the semantics of the destination depends on the target language: for
    86   the semantics of the destination depends on the target language: for
    88   @{text SML}, @{text OCaml} and @{text Scala} it denotes a \emph{file},
    87   \<open>SML\<close>, \<open>OCaml\<close> and \<open>Scala\<close> it denotes a \emph{file},
    89   for @{text Haskell} it denotes a \emph{directory} where a file named as the
    88   for \<open>Haskell\<close> it denotes a \emph{directory} where a file named as the
    90   module name (with extension @{text ".hs"}) is written:
    89   module name (with extension \<open>.hs\<close>) is written:
    91 \<close>
    90 \<close>
    92 
    91 
    93 export_code %quote empty dequeue enqueue in Haskell
    92 export_code %quote empty dequeue enqueue in Haskell
    94   module_name Example file "$ISABELLE_TMP/examples/"
    93   module_name Example file "$ISABELLE_TMP/examples/"
    95 
    94 
   177 \<close>
   176 \<close>
   178 
   177 
   179 text \<open>
   178 text \<open>
   180   \noindent This is a convenient place to show how explicit dictionary
   179   \noindent This is a convenient place to show how explicit dictionary
   181   construction manifests in generated code -- the same example in
   180   construction manifests in generated code -- the same example in
   182   @{text SML}:
   181   \<open>SML\<close>:
   183 \<close>
   182 \<close>
   184 
   183 
   185 text %quotetypewriter \<open>
   184 text %quotetypewriter \<open>
   186   @{code_stmts bexp (SML)}
   185   @{code_stmts bexp (SML)}
   187 \<close>
   186 \<close>