Theory Introduction
section ‹Dictionary Construction›
theory Introduction
imports Main
begin
subsection ‹Introduction›
text ‹
Isabelle's logic features \emph{type classes}~\<^cite>‹"haftmann2007typeclasses" and "wenzel1997typeclasses"›.
These are built into the kernel and are used extensively in theory developments.
The existing \emph{code generator}, when targeting Standard ML, performs the well-known dictionary
construction or \emph{dictionary translation}~\<^cite>‹"haftmann2010codegeneration"›.
This works by replacing type classes with records, instances with values, and occurrences with
explicit parameters.
Haftmann and Nipkow give a pen-and-paper correctness proof of this construction
\cite[‹§›4.1]{haftmann2010codegeneration}, based on a notion of \emph{higher-order rewrite
systems.}
The resulting theorem then states that any well-typed term is reduction-equivalent before and after
class elimination.
In this work, the dictionary construction is performed in a certified fashion, that is, the
equivalence is a theorem inside the logic.
›
subsection ‹Encoding classes›
text ‹
The choice of representation of a dictionary itself is straightforward: We model it as a
@{command datatype}, along with functions returning values of that type. The alternative here
would have been to use the @{command record} package. The obvious advantage is that we could
easily model subclass relationships through record inheritance. However, records do not support
multiple inheritance. Since records offer no advantage over datatypes in that regard, we opted for
the more modern @{command datatype} package.
›
text ‹Consider the following example:›
class plus =
fixes plus :: "'a ⇒ 'a ⇒ 'a"
text ‹
This will get translated to a @{command datatype} with a single constructor taking a single
argument:
›