Theory Introduction
theory Introduction
imports Setup
begin
ML ‹
Isabelle_System.make_directory (File.tmp_path (Path.basic "examples"))
›
section ‹Introduction›
text ‹
This tutorial introduces the code generator facilities of ‹Isabelle/HOL›. It allows to turn (a certain class of) HOL
specifications into corresponding executable code in the programming
languages ‹SML› \<^cite>‹SML›, ‹OCaml› \<^cite>‹OCaml›,
‹Haskell› \<^cite>‹"haskell-revised-report"› and ‹Scala›
\<^cite>‹"scala-overview-tech-report"›.
To profit from this tutorial, some familiarity and experience with
Isabelle/HOL \<^cite>‹"isa-tutorial"› and its basic theories is assumed.
›
subsection ‹Code generation principle: shallow embedding \label{sec:principle}›
text ‹
The key concept for understanding Isabelle's code generation is
\emph{shallow embedding}: logical entities like constants, types and
classes are identified with corresponding entities in the target
language. In particular, the carrier of a generated program's
semantics are \emph{equational theorems} from the logic. If we view
a generated program as an implementation of a higher-order rewrite
system, then every rewrite step performed by the program can be
simulated in the logic, which guarantees partial correctness
\<^cite>‹"Haftmann-Nipkow:2010:code"›.
›
subsection ‹A quick start with the Isabelle/HOL toolbox \label{sec:queue_example}›
text ‹
In a HOL theory, the @{command_def datatype} and @{command_def
definition}/@{command_def primrec}/@{command_def fun} declarations
form the core of a functional programming language. By default
equational theorems stemming from those are used for generated code,
therefore \qt{naive} code generation can proceed without further
ado.
For example, here a simple \qt{implementation} of amortised queues:
›