10305
|
1 |
\chapter{More about Types}
|
10539
|
2 |
\label{ch:more-types}
|
10305
|
3 |
|
|
4 |
So far we have learned about a few basic types (for example \isa{bool} and
|
|
5 |
\isa{nat}), type abbreviations (\isacommand{types}) and recursive datatpes
|
10885
|
6 |
(\isacommand{datatype}). This chapter will introduce more
|
10305
|
7 |
advanced material:
|
|
8 |
\begin{itemize}
|
|
9 |
\item More about basic types: numbers ({\S}\ref{sec:numbers}), pairs
|
10538
|
10 |
({\S}\ref{sec:products}) and records ({\S}\ref{sec:records}), and how to
|
|
11 |
reason about them.
|
11149
|
12 |
\item Type classes: how to specify and reason about axiomatic collections of
|
|
13 |
types ({\S}\ref{sec:axclass}).
|
10885
|
14 |
\item Introducing your own types: how to introduce new types that
|
10538
|
15 |
cannot be constructed with any of the basic methods
|
|
16 |
({\S}\ref{sec:adv-typedef}).
|
10305
|
17 |
\end{itemize}
|
|
18 |
|
11149
|
19 |
The material in this section goes beyond the needs of most novices. Serious
|
|
20 |
users should at least skim the sections on basic types and on type classes.
|
|
21 |
The latter is fairly advanced: read the beginning to understand what it is
|
|
22 |
about, but consult the rest only when necessary.
|
|
23 |
|
10538
|
24 |
\section{Numbers}
|
10396
|
25 |
\label{sec:numbers}
|
|
26 |
|
10595
|
27 |
\input{Types/numerics}
|
|
28 |
|
10543
|
29 |
\index{pair|(}
|
10538
|
30 |
\input{Types/document/Pairs}
|
10543
|
31 |
\index{pair|)}
|
10396
|
32 |
|
10538
|
33 |
\section{Records}
|
10396
|
34 |
\label{sec:records}
|
|
35 |
|
10305
|
36 |
\section{Axiomatic type classes}
|
|
37 |
\label{sec:axclass}
|
|
38 |
\index{axiomatic type class|(}
|
|
39 |
\index{*axclass|(}
|
|
40 |
|
|
41 |
|
|
42 |
The programming language Haskell has popularized the notion of type classes.
|
|
43 |
Isabelle offers the related concept of an \textbf{axiomatic type class}.
|
|
44 |
Roughly speaking, an axiomatic type class is a type class with axioms, i.e.\
|
|
45 |
an axiomatic specification of a class of types. Thus we can talk about a type
|
11213
|
46 |
$\tau$ being in a class $C$, which is written $\tau :: C$. This is the case if
|
11196
|
47 |
$\tau$ satisfies the axioms of $C$. Furthermore, type classes can be
|
|
48 |
organized in a hierarchy. Thus there is the notion of a class $D$ being a
|
|
49 |
\textbf{subclass} of a class $C$, written $D < C$. This is the case if all
|
|
50 |
axioms of $C$ are also provable in $D$. We introduce these concepts
|
10305
|
51 |
by means of a running example, ordering relations.
|
|
52 |
|
|
53 |
\subsection{Overloading}
|
|
54 |
\label{sec:overloading}
|
|
55 |
\index{overloading|(}
|
|
56 |
|
|
57 |
\input{Types/document/Overloading0}
|
|
58 |
\input{Types/document/Overloading1}
|
|
59 |
\input{Types/document/Overloading}
|
|
60 |
\input{Types/document/Overloading2}
|
|
61 |
|
|
62 |
\index{overloading|)}
|
|
63 |
|
10362
|
64 |
\input{Types/document/Axioms}
|
10305
|
65 |
|
|
66 |
\index{axiomatic type class|)}
|
|
67 |
\index{*axclass|)}
|
11149
|
68 |
|
|
69 |
|
|
70 |
\input{Types/document/Typedef}
|