doc-src/IsarRef/Thy/document/HOL_Specific.tex
changeset 37397 6d19e4e6ebf5
parent 37395 1cf6f134e7f2
child 37419 2e7e7ff21e25
     1.1 --- a/doc-src/IsarRef/Thy/document/HOL_Specific.tex	Mon Jun 14 10:38:29 2010 +0200
     1.2 +++ b/doc-src/IsarRef/Thy/document/HOL_Specific.tex	Mon Jun 14 10:50:49 2010 +0200
     1.3 @@ -981,7 +981,211 @@
     1.4    instantiates these mechanisms in a way that is amenable to end-user
     1.5    applications.
     1.6  
     1.7 -  One framework generates code from both functional and relational
     1.8 +  \medskip One framework generates code from functional programs
     1.9 +  (including overloading using type classes) to SML \cite{SML}, OCaml
    1.10 +  \cite{OCaml} and Haskell \cite{haskell-revised-report}.
    1.11 +  Conceptually, code generation is split up in three steps:
    1.12 +  \emph{selection} of code theorems, \emph{translation} into an
    1.13 +  abstract executable view and \emph{serialization} to a specific
    1.14 +  \emph{target language}.  Inductive specifications can be executed
    1.15 +  using the predicate compiler which operates within HOL.
    1.16 +  See \cite{isabelle-codegen} for an introduction.
    1.17 +
    1.18 +  \begin{matharray}{rcl}
    1.19 +    \indexdef{HOL}{command}{export\_code}\hypertarget{command.HOL.export-code}{\hyperlink{command.HOL.export-code}{\mbox{\isa{\isacommand{export{\isacharunderscore}code}}}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isa{{\isachardoublequote}context\ {\isasymrightarrow}{\isachardoublequote}} \\
    1.20 +    \indexdef{HOL}{attribute}{code}\hypertarget{attribute.HOL.code}{\hyperlink{attribute.HOL.code}{\mbox{\isa{code}}}} & : & \isa{attribute} \\
    1.21 +    \indexdef{HOL}{command}{code\_abort}\hypertarget{command.HOL.code-abort}{\hyperlink{command.HOL.code-abort}{\mbox{\isa{\isacommand{code{\isacharunderscore}abort}}}}} & : & \isa{{\isachardoublequote}theory\ {\isasymrightarrow}\ theory{\isachardoublequote}} \\
    1.22 +    \indexdef{HOL}{command}{code\_datatype}\hypertarget{command.HOL.code-datatype}{\hyperlink{command.HOL.code-datatype}{\mbox{\isa{\isacommand{code{\isacharunderscore}datatype}}}}} & : & \isa{{\isachardoublequote}theory\ {\isasymrightarrow}\ theory{\isachardoublequote}} \\
    1.23 +    \indexdef{HOL}{command}{print\_codesetup}\hypertarget{command.HOL.print-codesetup}{\hyperlink{command.HOL.print-codesetup}{\mbox{\isa{\isacommand{print{\isacharunderscore}codesetup}}}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isa{{\isachardoublequote}context\ {\isasymrightarrow}{\isachardoublequote}} \\
    1.24 +    \indexdef{HOL}{attribute}{code\_inline}\hypertarget{attribute.HOL.code-inline}{\hyperlink{attribute.HOL.code-inline}{\mbox{\isa{code{\isacharunderscore}inline}}}} & : & \isa{attribute} \\
    1.25 +    \indexdef{HOL}{attribute}{code\_post}\hypertarget{attribute.HOL.code-post}{\hyperlink{attribute.HOL.code-post}{\mbox{\isa{code{\isacharunderscore}post}}}} & : & \isa{attribute} \\
    1.26 +    \indexdef{HOL}{command}{print\_codeproc}\hypertarget{command.HOL.print-codeproc}{\hyperlink{command.HOL.print-codeproc}{\mbox{\isa{\isacommand{print{\isacharunderscore}codeproc}}}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isa{{\isachardoublequote}context\ {\isasymrightarrow}{\isachardoublequote}} \\
    1.27 +    \indexdef{HOL}{command}{code\_thms}\hypertarget{command.HOL.code-thms}{\hyperlink{command.HOL.code-thms}{\mbox{\isa{\isacommand{code{\isacharunderscore}thms}}}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isa{{\isachardoublequote}context\ {\isasymrightarrow}{\isachardoublequote}} \\
    1.28 +    \indexdef{HOL}{command}{code\_deps}\hypertarget{command.HOL.code-deps}{\hyperlink{command.HOL.code-deps}{\mbox{\isa{\isacommand{code{\isacharunderscore}deps}}}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isa{{\isachardoublequote}context\ {\isasymrightarrow}{\isachardoublequote}} \\
    1.29 +    \indexdef{HOL}{command}{code\_const}\hypertarget{command.HOL.code-const}{\hyperlink{command.HOL.code-const}{\mbox{\isa{\isacommand{code{\isacharunderscore}const}}}}} & : & \isa{{\isachardoublequote}theory\ {\isasymrightarrow}\ theory{\isachardoublequote}} \\
    1.30 +    \indexdef{HOL}{command}{code\_type}\hypertarget{command.HOL.code-type}{\hyperlink{command.HOL.code-type}{\mbox{\isa{\isacommand{code{\isacharunderscore}type}}}}} & : & \isa{{\isachardoublequote}theory\ {\isasymrightarrow}\ theory{\isachardoublequote}} \\
    1.31 +    \indexdef{HOL}{command}{code\_class}\hypertarget{command.HOL.code-class}{\hyperlink{command.HOL.code-class}{\mbox{\isa{\isacommand{code{\isacharunderscore}class}}}}} & : & \isa{{\isachardoublequote}theory\ {\isasymrightarrow}\ theory{\isachardoublequote}} \\
    1.32 +    \indexdef{HOL}{command}{code\_instance}\hypertarget{command.HOL.code-instance}{\hyperlink{command.HOL.code-instance}{\mbox{\isa{\isacommand{code{\isacharunderscore}instance}}}}} & : & \isa{{\isachardoublequote}theory\ {\isasymrightarrow}\ theory{\isachardoublequote}} \\
    1.33 +    \indexdef{HOL}{command}{code\_reserved}\hypertarget{command.HOL.code-reserved}{\hyperlink{command.HOL.code-reserved}{\mbox{\isa{\isacommand{code{\isacharunderscore}reserved}}}}} & : & \isa{{\isachardoublequote}theory\ {\isasymrightarrow}\ theory{\isachardoublequote}} \\
    1.34 +    \indexdef{HOL}{command}{code\_monad}\hypertarget{command.HOL.code-monad}{\hyperlink{command.HOL.code-monad}{\mbox{\isa{\isacommand{code{\isacharunderscore}monad}}}}} & : & \isa{{\isachardoublequote}theory\ {\isasymrightarrow}\ theory{\isachardoublequote}} \\
    1.35 +    \indexdef{HOL}{command}{code\_include}\hypertarget{command.HOL.code-include}{\hyperlink{command.HOL.code-include}{\mbox{\isa{\isacommand{code{\isacharunderscore}include}}}}} & : & \isa{{\isachardoublequote}theory\ {\isasymrightarrow}\ theory{\isachardoublequote}} \\
    1.36 +    \indexdef{HOL}{command}{code\_modulename}\hypertarget{command.HOL.code-modulename}{\hyperlink{command.HOL.code-modulename}{\mbox{\isa{\isacommand{code{\isacharunderscore}modulename}}}}} & : & \isa{{\isachardoublequote}theory\ {\isasymrightarrow}\ theory{\isachardoublequote}} \\
    1.37 +  \end{matharray}
    1.38 +
    1.39 +  \begin{rail}
    1.40 +    'export\_code' ( constexpr + ) \\
    1.41 +      ( ( 'in' target ( 'module\_name' string ) ? \\
    1.42 +        ( 'file' ( string | '-' ) ) ? ( '(' args ')' ) ?) + ) ?
    1.43 +    ;
    1.44 +
    1.45 +    const: term
    1.46 +    ;
    1.47 +
    1.48 +    constexpr: ( const | 'name.*' | '*' )
    1.49 +    ;
    1.50 +
    1.51 +    typeconstructor: nameref
    1.52 +    ;
    1.53 +
    1.54 +    class: nameref
    1.55 +    ;
    1.56 +
    1.57 +    target: 'OCaml' | 'SML' | 'Haskell'
    1.58 +    ;
    1.59 +
    1.60 +    'code' ( 'del' ) ?
    1.61 +    ;
    1.62 +
    1.63 +    'code\_abort' ( const + )
    1.64 +    ;
    1.65 +
    1.66 +    'code\_datatype' ( const + )
    1.67 +    ;
    1.68 +
    1.69 +    'code_inline' ( 'del' ) ?
    1.70 +    ;
    1.71 +
    1.72 +    'code_post' ( 'del' ) ?
    1.73 +    ;
    1.74 +
    1.75 +    'code\_thms' ( constexpr + ) ?
    1.76 +    ;
    1.77 +
    1.78 +    'code\_deps' ( constexpr + ) ?
    1.79 +    ;
    1.80 +
    1.81 +    'code\_const' (const + 'and') \\
    1.82 +      ( ( '(' target ( syntax ? + 'and' ) ')' ) + )
    1.83 +    ;
    1.84 +
    1.85 +    'code\_type' (typeconstructor + 'and') \\
    1.86 +      ( ( '(' target ( syntax ? + 'and' ) ')' ) + )
    1.87 +    ;
    1.88 +
    1.89 +    'code\_class' (class + 'and') \\
    1.90 +      ( ( '(' target \\ ( string ? + 'and' ) ')' ) + )
    1.91 +    ;
    1.92 +
    1.93 +    'code\_instance' (( typeconstructor '::' class ) + 'and') \\
    1.94 +      ( ( '(' target ( '-' ? + 'and' ) ')' ) + )
    1.95 +    ;
    1.96 +
    1.97 +    'code\_reserved' target ( string + )
    1.98 +    ;
    1.99 +
   1.100 +    'code\_monad' const const target
   1.101 +    ;
   1.102 +
   1.103 +    'code\_include' target ( string ( string | '-') )
   1.104 +    ;
   1.105 +
   1.106 +    'code\_modulename' target ( ( string string ) + )
   1.107 +    ;
   1.108 +
   1.109 +    syntax: string | ( 'infix' | 'infixl' | 'infixr' ) nat string
   1.110 +    ;
   1.111 +
   1.112 +  \end{rail}
   1.113 +
   1.114 +  \begin{description}
   1.115 +
   1.116 +  \item \hyperlink{command.HOL.export-code}{\mbox{\isa{\isacommand{export{\isacharunderscore}code}}}} generates code for a given list
   1.117 +  of constants in the specified target language(s).  If no serialization
   1.118 +  instruction is given, only abstract code is generated internally.
   1.119 +
   1.120 +  Constants may be specified by giving them literally, referring to
   1.121 +  all executable contants within a certain theory by giving \isa{{\isachardoublequote}name{\isachardot}{\isacharasterisk}{\isachardoublequote}}, or referring to \emph{all} executable constants currently
   1.122 +  available by giving \isa{{\isachardoublequote}{\isacharasterisk}{\isachardoublequote}}.
   1.123 +
   1.124 +  By default, for each involved theory one corresponding name space
   1.125 +  module is generated.  Alternativly, a module name may be specified
   1.126 +  after the \hyperlink{keyword.module-name}{\mbox{\isa{\isakeyword{module{\isacharunderscore}name}}}} keyword; then \emph{all} code is
   1.127 +  placed in this module.
   1.128 +
   1.129 +  For \emph{SML} and \emph{OCaml}, the file specification refers to a
   1.130 +  single file; for \emph{Haskell}, it refers to a whole directory,
   1.131 +  where code is generated in multiple files reflecting the module
   1.132 +  hierarchy.  The file specification ``\isa{{\isachardoublequote}{\isacharminus}{\isachardoublequote}}'' denotes standard
   1.133 +  output.  For \emph{SML}, omitting the file specification compiles
   1.134 +  code internally in the context of the current ML session.
   1.135 +
   1.136 +  Serializers take an optional list of arguments in parentheses.  For
   1.137 +  \emph{SML} and \emph{OCaml}, ``\isa{no{\isacharunderscore}signatures}`` omits
   1.138 +  explicit module signatures.
   1.139 +  
   1.140 +  For \emph{Haskell} a module name prefix may be given using the ``\isa{{\isachardoublequote}root{\isacharcolon}{\isachardoublequote}}'' argument; ``\isa{string{\isacharunderscore}classes}'' adds a ``\verb|deriving (Read, Show)|'' clause to each appropriate datatype
   1.141 +  declaration.
   1.142 +
   1.143 +  \item \hyperlink{attribute.HOL.code}{\mbox{\isa{code}}} explicitly selects (or with option
   1.144 +  ``\isa{{\isachardoublequote}del{\isachardoublequote}}'' deselects) a code equation for code
   1.145 +  generation.  Usually packages introducing code equations provide
   1.146 +  a reasonable default setup for selection.
   1.147 +
   1.148 +  \item \hyperlink{command.HOL.code-abort}{\mbox{\isa{\isacommand{code{\isacharunderscore}abort}}}} declares constants which are not
   1.149 +  required to have a definition by means of code equations; if
   1.150 +  needed these are implemented by program abort instead.
   1.151 +
   1.152 +  \item \hyperlink{command.HOL.code-datatype}{\mbox{\isa{\isacommand{code{\isacharunderscore}datatype}}}} specifies a constructor set
   1.153 +  for a logical type.
   1.154 +
   1.155 +  \item \hyperlink{command.HOL.print-codesetup}{\mbox{\isa{\isacommand{print{\isacharunderscore}codesetup}}}} gives an overview on
   1.156 +  selected code equations and code generator datatypes.
   1.157 +
   1.158 +  \item \hyperlink{attribute.HOL.code-inline}{\mbox{\isa{code{\isacharunderscore}inline}}} declares (or with
   1.159 +  option ``\isa{{\isachardoublequote}del{\isachardoublequote}}'' removes) inlining theorems which are
   1.160 +  applied as rewrite rules to any code equation during
   1.161 +  preprocessing.
   1.162 +
   1.163 +  \item \hyperlink{attribute.HOL.code-post}{\mbox{\isa{code{\isacharunderscore}post}}} declares (or with
   1.164 +  option ``\isa{{\isachardoublequote}del{\isachardoublequote}}'' removes) theorems which are
   1.165 +  applied as rewrite rules to any result of an evaluation.
   1.166 +
   1.167 +  \item \hyperlink{command.HOL.print-codeproc}{\mbox{\isa{\isacommand{print{\isacharunderscore}codeproc}}}} prints the setup
   1.168 +  of the code generator preprocessor.
   1.169 +
   1.170 +  \item \hyperlink{command.HOL.code-thms}{\mbox{\isa{\isacommand{code{\isacharunderscore}thms}}}} prints a list of theorems
   1.171 +  representing the corresponding program containing all given
   1.172 +  constants after preprocessing.
   1.173 +
   1.174 +  \item \hyperlink{command.HOL.code-deps}{\mbox{\isa{\isacommand{code{\isacharunderscore}deps}}}} visualizes dependencies of
   1.175 +  theorems representing the corresponding program containing all given
   1.176 +  constants after preprocessing.
   1.177 +
   1.178 +  \item \hyperlink{command.HOL.code-const}{\mbox{\isa{\isacommand{code{\isacharunderscore}const}}}} associates a list of constants
   1.179 +  with target-specific serializations; omitting a serialization
   1.180 +  deletes an existing serialization.
   1.181 +
   1.182 +  \item \hyperlink{command.HOL.code-type}{\mbox{\isa{\isacommand{code{\isacharunderscore}type}}}} associates a list of type
   1.183 +  constructors with target-specific serializations; omitting a
   1.184 +  serialization deletes an existing serialization.
   1.185 +
   1.186 +  \item \hyperlink{command.HOL.code-class}{\mbox{\isa{\isacommand{code{\isacharunderscore}class}}}} associates a list of classes
   1.187 +  with target-specific class names; omitting a serialization deletes
   1.188 +  an existing serialization.  This applies only to \emph{Haskell}.
   1.189 +
   1.190 +  \item \hyperlink{command.HOL.code-instance}{\mbox{\isa{\isacommand{code{\isacharunderscore}instance}}}} declares a list of type
   1.191 +  constructor / class instance relations as ``already present'' for a
   1.192 +  given target.  Omitting a ``\isa{{\isachardoublequote}{\isacharminus}{\isachardoublequote}}'' deletes an existing
   1.193 +  ``already present'' declaration.  This applies only to
   1.194 +  \emph{Haskell}.
   1.195 +
   1.196 +  \item \hyperlink{command.HOL.code-reserved}{\mbox{\isa{\isacommand{code{\isacharunderscore}reserved}}}} declares a list of names as
   1.197 +  reserved for a given target, preventing it to be shadowed by any
   1.198 +  generated code.
   1.199 +
   1.200 +  \item \hyperlink{command.HOL.code-monad}{\mbox{\isa{\isacommand{code{\isacharunderscore}monad}}}} provides an auxiliary mechanism
   1.201 +  to generate monadic code for Haskell.
   1.202 +
   1.203 +  \item \hyperlink{command.HOL.code-include}{\mbox{\isa{\isacommand{code{\isacharunderscore}include}}}} adds arbitrary named content
   1.204 +  (``include'') to generated code.  A ``\isa{{\isachardoublequote}{\isacharminus}{\isachardoublequote}}'' as last argument
   1.205 +  will remove an already added ``include''.
   1.206 +
   1.207 +  \item \hyperlink{command.HOL.code-modulename}{\mbox{\isa{\isacommand{code{\isacharunderscore}modulename}}}} declares aliasings from one
   1.208 +  module name onto another.
   1.209 +
   1.210 +  \end{description}
   1.211 +
   1.212 +  The other framework generates code from both functional and relational
   1.213    programs to SML.  See \cite{isabelle-HOL} for further information
   1.214    (this actually covers the new-style theory format as well).
   1.215  
   1.216 @@ -1025,208 +1229,7 @@
   1.217  
   1.218    'code' (name)?
   1.219    ;
   1.220 -  \end{rail}
   1.221 -
   1.222 -  \medskip The other framework generates code from functional programs
   1.223 -  (including overloading using type classes) to SML \cite{SML}, OCaml
   1.224 -  \cite{OCaml} and Haskell \cite{haskell-revised-report}.
   1.225 -  Conceptually, code generation is split up in three steps:
   1.226 -  \emph{selection} of code theorems, \emph{translation} into an
   1.227 -  abstract executable view and \emph{serialization} to a specific
   1.228 -  \emph{target language}.  See \cite{isabelle-codegen} for an
   1.229 -  introduction on how to use it.
   1.230 -
   1.231 -  \begin{matharray}{rcl}
   1.232 -    \indexdef{HOL}{command}{export\_code}\hypertarget{command.HOL.export-code}{\hyperlink{command.HOL.export-code}{\mbox{\isa{\isacommand{export{\isacharunderscore}code}}}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isa{{\isachardoublequote}context\ {\isasymrightarrow}{\isachardoublequote}} \\
   1.233 -    \indexdef{HOL}{command}{code\_thms}\hypertarget{command.HOL.code-thms}{\hyperlink{command.HOL.code-thms}{\mbox{\isa{\isacommand{code{\isacharunderscore}thms}}}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isa{{\isachardoublequote}context\ {\isasymrightarrow}{\isachardoublequote}} \\
   1.234 -    \indexdef{HOL}{command}{code\_deps}\hypertarget{command.HOL.code-deps}{\hyperlink{command.HOL.code-deps}{\mbox{\isa{\isacommand{code{\isacharunderscore}deps}}}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isa{{\isachardoublequote}context\ {\isasymrightarrow}{\isachardoublequote}} \\
   1.235 -    \indexdef{HOL}{command}{code\_datatype}\hypertarget{command.HOL.code-datatype}{\hyperlink{command.HOL.code-datatype}{\mbox{\isa{\isacommand{code{\isacharunderscore}datatype}}}}} & : & \isa{{\isachardoublequote}theory\ {\isasymrightarrow}\ theory{\isachardoublequote}} \\
   1.236 -    \indexdef{HOL}{command}{code\_const}\hypertarget{command.HOL.code-const}{\hyperlink{command.HOL.code-const}{\mbox{\isa{\isacommand{code{\isacharunderscore}const}}}}} & : & \isa{{\isachardoublequote}theory\ {\isasymrightarrow}\ theory{\isachardoublequote}} \\
   1.237 -    \indexdef{HOL}{command}{code\_type}\hypertarget{command.HOL.code-type}{\hyperlink{command.HOL.code-type}{\mbox{\isa{\isacommand{code{\isacharunderscore}type}}}}} & : & \isa{{\isachardoublequote}theory\ {\isasymrightarrow}\ theory{\isachardoublequote}} \\
   1.238 -    \indexdef{HOL}{command}{code\_class}\hypertarget{command.HOL.code-class}{\hyperlink{command.HOL.code-class}{\mbox{\isa{\isacommand{code{\isacharunderscore}class}}}}} & : & \isa{{\isachardoublequote}theory\ {\isasymrightarrow}\ theory{\isachardoublequote}} \\
   1.239 -    \indexdef{HOL}{command}{code\_instance}\hypertarget{command.HOL.code-instance}{\hyperlink{command.HOL.code-instance}{\mbox{\isa{\isacommand{code{\isacharunderscore}instance}}}}} & : & \isa{{\isachardoublequote}theory\ {\isasymrightarrow}\ theory{\isachardoublequote}} \\
   1.240 -    \indexdef{HOL}{command}{code\_monad}\hypertarget{command.HOL.code-monad}{\hyperlink{command.HOL.code-monad}{\mbox{\isa{\isacommand{code{\isacharunderscore}monad}}}}} & : & \isa{{\isachardoublequote}theory\ {\isasymrightarrow}\ theory{\isachardoublequote}} \\
   1.241 -    \indexdef{HOL}{command}{code\_reserved}\hypertarget{command.HOL.code-reserved}{\hyperlink{command.HOL.code-reserved}{\mbox{\isa{\isacommand{code{\isacharunderscore}reserved}}}}} & : & \isa{{\isachardoublequote}theory\ {\isasymrightarrow}\ theory{\isachardoublequote}} \\
   1.242 -    \indexdef{HOL}{command}{code\_include}\hypertarget{command.HOL.code-include}{\hyperlink{command.HOL.code-include}{\mbox{\isa{\isacommand{code{\isacharunderscore}include}}}}} & : & \isa{{\isachardoublequote}theory\ {\isasymrightarrow}\ theory{\isachardoublequote}} \\
   1.243 -    \indexdef{HOL}{command}{code\_modulename}\hypertarget{command.HOL.code-modulename}{\hyperlink{command.HOL.code-modulename}{\mbox{\isa{\isacommand{code{\isacharunderscore}modulename}}}}} & : & \isa{{\isachardoublequote}theory\ {\isasymrightarrow}\ theory{\isachardoublequote}} \\
   1.244 -    \indexdef{HOL}{command}{code\_abort}\hypertarget{command.HOL.code-abort}{\hyperlink{command.HOL.code-abort}{\mbox{\isa{\isacommand{code{\isacharunderscore}abort}}}}} & : & \isa{{\isachardoublequote}theory\ {\isasymrightarrow}\ theory{\isachardoublequote}} \\
   1.245 -    \indexdef{HOL}{command}{print\_codesetup}\hypertarget{command.HOL.print-codesetup}{\hyperlink{command.HOL.print-codesetup}{\mbox{\isa{\isacommand{print{\isacharunderscore}codesetup}}}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isa{{\isachardoublequote}context\ {\isasymrightarrow}{\isachardoublequote}} \\
   1.246 -    \indexdef{HOL}{command}{print\_codeproc}\hypertarget{command.HOL.print-codeproc}{\hyperlink{command.HOL.print-codeproc}{\mbox{\isa{\isacommand{print{\isacharunderscore}codeproc}}}}}\isa{{\isachardoublequote}\isactrlsup {\isacharasterisk}{\isachardoublequote}} & : & \isa{{\isachardoublequote}context\ {\isasymrightarrow}{\isachardoublequote}} \\
   1.247 -    \indexdef{HOL}{attribute}{code}\hypertarget{attribute.HOL.code}{\hyperlink{attribute.HOL.code}{\mbox{\isa{code}}}} & : & \isa{attribute} \\
   1.248 -  \end{matharray}
   1.249 -
   1.250 -  \begin{rail}
   1.251 -    'export\_code' ( constexpr + ) \\
   1.252 -      ( ( 'in' target ( 'module\_name' string ) ? \\
   1.253 -        ( 'file' ( string | '-' ) ) ? ( '(' args ')' ) ?) + ) ?
   1.254 -    ;
   1.255 -
   1.256 -    'code\_thms' ( constexpr + ) ?
   1.257 -    ;
   1.258 -
   1.259 -    'code\_deps' ( constexpr + ) ?
   1.260 -    ;
   1.261 -
   1.262 -    const: term
   1.263 -    ;
   1.264 -
   1.265 -    constexpr: ( const | 'name.*' | '*' )
   1.266 -    ;
   1.267 -
   1.268 -    typeconstructor: nameref
   1.269 -    ;
   1.270 -
   1.271 -    class: nameref
   1.272 -    ;
   1.273 -
   1.274 -    target: 'OCaml' | 'SML' | 'Haskell'
   1.275 -    ;
   1.276 -
   1.277 -    'code\_datatype' ( const + )
   1.278 -    ;
   1.279 -
   1.280 -    'code\_const' (const + 'and') \\
   1.281 -      ( ( '(' target ( syntax ? + 'and' ) ')' ) + )
   1.282 -    ;
   1.283 -
   1.284 -    'code\_type' (typeconstructor + 'and') \\
   1.285 -      ( ( '(' target ( syntax ? + 'and' ) ')' ) + )
   1.286 -    ;
   1.287 -
   1.288 -    'code\_class' (class + 'and') \\
   1.289 -      ( ( '(' target \\ ( string ? + 'and' ) ')' ) + )
   1.290 -    ;
   1.291 -
   1.292 -    'code\_instance' (( typeconstructor '::' class ) + 'and') \\
   1.293 -      ( ( '(' target ( '-' ? + 'and' ) ')' ) + )
   1.294 -    ;
   1.295 -
   1.296 -    'code\_monad' const const target
   1.297 -    ;
   1.298 -
   1.299 -    'code\_reserved' target ( string + )
   1.300 -    ;
   1.301 -
   1.302 -    'code\_include' target ( string ( string | '-') )
   1.303 -    ;
   1.304 -
   1.305 -    'code\_modulename' target ( ( string string ) + )
   1.306 -    ;
   1.307 -
   1.308 -    'code\_abort' ( const + )
   1.309 -    ;
   1.310 -
   1.311 -    syntax: string | ( 'infix' | 'infixl' | 'infixr' ) nat string
   1.312 -    ;
   1.313 -
   1.314 -    'code' ( 'del' ) ?
   1.315 -    ;
   1.316 -
   1.317 -    'code_unfold' ( 'del' ) ?
   1.318 -    ;
   1.319 -
   1.320 -    'code_post' ( 'del' ) ?
   1.321 -    ;
   1.322 -  \end{rail}
   1.323 -
   1.324 -  \begin{description}
   1.325 -
   1.326 -  \item \hyperlink{command.HOL.export-code}{\mbox{\isa{\isacommand{export{\isacharunderscore}code}}}} is the canonical interface for
   1.327 -  generating and serializing code: for a given list of constants, code
   1.328 -  is generated for the specified target languages.  If no serialization
   1.329 -  instruction is given, only abstract code is generated internally.
   1.330 -
   1.331 -  Constants may be specified by giving them literally, referring to
   1.332 -  all executable contants within a certain theory by giving \isa{{\isachardoublequote}name{\isachardot}{\isacharasterisk}{\isachardoublequote}}, or referring to \emph{all} executable constants currently
   1.333 -  available by giving \isa{{\isachardoublequote}{\isacharasterisk}{\isachardoublequote}}.
   1.334 -
   1.335 -  By default, for each involved theory one corresponding name space
   1.336 -  module is generated.  Alternativly, a module name may be specified
   1.337 -  after the \hyperlink{keyword.module-name}{\mbox{\isa{\isakeyword{module{\isacharunderscore}name}}}} keyword; then \emph{all} code is
   1.338 -  placed in this module.
   1.339 -
   1.340 -  For \emph{SML} and \emph{OCaml}, the file specification refers to a
   1.341 -  single file; for \emph{Haskell}, it refers to a whole directory,
   1.342 -  where code is generated in multiple files reflecting the module
   1.343 -  hierarchy.  The file specification ``\isa{{\isachardoublequote}{\isacharminus}{\isachardoublequote}}'' denotes standard
   1.344 -  output.  For \emph{SML}, omitting the file specification compiles
   1.345 -  code internally in the context of the current ML session.
   1.346 -
   1.347 -  Serializers take an optional list of arguments in parentheses.  For
   1.348 -  \emph{SML} and \emph{OCaml}, ``\isa{no{\isacharunderscore}signatures}`` omits
   1.349 -  explicit module signatures.
   1.350 -  
   1.351 -  For \emph{Haskell} a module name prefix may be given using the ``\isa{{\isachardoublequote}root{\isacharcolon}{\isachardoublequote}}'' argument; ``\isa{string{\isacharunderscore}classes}'' adds a ``\verb|deriving (Read, Show)|'' clause to each appropriate datatype
   1.352 -  declaration.
   1.353 -
   1.354 -  \item \hyperlink{command.HOL.code-thms}{\mbox{\isa{\isacommand{code{\isacharunderscore}thms}}}} prints a list of theorems
   1.355 -  representing the corresponding program containing all given
   1.356 -  constants.
   1.357 -
   1.358 -  \item \hyperlink{command.HOL.code-deps}{\mbox{\isa{\isacommand{code{\isacharunderscore}deps}}}} visualizes dependencies of
   1.359 -  theorems representing the corresponding program containing all given
   1.360 -  constants.
   1.361 -
   1.362 -  \item \hyperlink{command.HOL.code-datatype}{\mbox{\isa{\isacommand{code{\isacharunderscore}datatype}}}} specifies a constructor set
   1.363 -  for a logical type.
   1.364 -
   1.365 -  \item \hyperlink{command.HOL.code-const}{\mbox{\isa{\isacommand{code{\isacharunderscore}const}}}} associates a list of constants
   1.366 -  with target-specific serializations; omitting a serialization
   1.367 -  deletes an existing serialization.
   1.368 -
   1.369 -  \item \hyperlink{command.HOL.code-type}{\mbox{\isa{\isacommand{code{\isacharunderscore}type}}}} associates a list of type
   1.370 -  constructors with target-specific serializations; omitting a
   1.371 -  serialization deletes an existing serialization.
   1.372 -
   1.373 -  \item \hyperlink{command.HOL.code-class}{\mbox{\isa{\isacommand{code{\isacharunderscore}class}}}} associates a list of classes
   1.374 -  with target-specific class names; omitting a serialization deletes
   1.375 -  an existing serialization.  This applies only to \emph{Haskell}.
   1.376 -
   1.377 -  \item \hyperlink{command.HOL.code-instance}{\mbox{\isa{\isacommand{code{\isacharunderscore}instance}}}} declares a list of type
   1.378 -  constructor / class instance relations as ``already present'' for a
   1.379 -  given target.  Omitting a ``\isa{{\isachardoublequote}{\isacharminus}{\isachardoublequote}}'' deletes an existing
   1.380 -  ``already present'' declaration.  This applies only to
   1.381 -  \emph{Haskell}.
   1.382 -
   1.383 -  \item \hyperlink{command.HOL.code-monad}{\mbox{\isa{\isacommand{code{\isacharunderscore}monad}}}} provides an auxiliary mechanism
   1.384 -  to generate monadic code for Haskell.
   1.385 -
   1.386 -  \item \hyperlink{command.HOL.code-reserved}{\mbox{\isa{\isacommand{code{\isacharunderscore}reserved}}}} declares a list of names as
   1.387 -  reserved for a given target, preventing it to be shadowed by any
   1.388 -  generated code.
   1.389 -
   1.390 -  \item \hyperlink{command.HOL.code-include}{\mbox{\isa{\isacommand{code{\isacharunderscore}include}}}} adds arbitrary named content
   1.391 -  (``include'') to generated code.  A ``\isa{{\isachardoublequote}{\isacharminus}{\isachardoublequote}}'' as last argument
   1.392 -  will remove an already added ``include''.
   1.393 -
   1.394 -  \item \hyperlink{command.HOL.code-modulename}{\mbox{\isa{\isacommand{code{\isacharunderscore}modulename}}}} declares aliasings from one
   1.395 -  module name onto another.
   1.396 -
   1.397 -  \item \hyperlink{command.HOL.code-abort}{\mbox{\isa{\isacommand{code{\isacharunderscore}abort}}}} declares constants which are not
   1.398 -  required to have a definition by means of code equations; if
   1.399 -  needed these are implemented by program abort instead.
   1.400 -
   1.401 -  \item \hyperlink{attribute.HOL.code}{\mbox{\isa{code}}} explicitly selects (or with option
   1.402 -  ``\isa{{\isachardoublequote}del{\isachardoublequote}}'' deselects) a code equation for code
   1.403 -  generation.  Usually packages introducing code equations provide
   1.404 -  a reasonable default setup for selection.
   1.405 -
   1.406 -  \item \hyperlink{attribute.HOL.code-inline}{\mbox{\isa{code{\isacharunderscore}inline}}} declares (or with
   1.407 -  option ``\isa{{\isachardoublequote}del{\isachardoublequote}}'' removes) inlining theorems which are
   1.408 -  applied as rewrite rules to any code equation during
   1.409 -  preprocessing.
   1.410 -
   1.411 -  \item \hyperlink{attribute.HOL.code-post}{\mbox{\isa{code{\isacharunderscore}post}}} declares (or with
   1.412 -  option ``\isa{{\isachardoublequote}del{\isachardoublequote}}'' removes) theorems which are
   1.413 -  applied as rewrite rules to any result of an evaluation.
   1.414 -
   1.415 -  \item \hyperlink{command.HOL.print-codesetup}{\mbox{\isa{\isacommand{print{\isacharunderscore}codesetup}}}} gives an overview on
   1.416 -  selected code equations and code generator datatypes.
   1.417 -
   1.418 -  \item \hyperlink{command.HOL.print-codeproc}{\mbox{\isa{\isacommand{print{\isacharunderscore}codeproc}}}} prints the setup
   1.419 -  of the code generator preprocessor.
   1.420 -
   1.421 -  \end{description}%
   1.422 +  \end{rail}%
   1.423  \end{isamarkuptext}%
   1.424  \isamarkuptrue%
   1.425  %