doc-src/TutorialI/Types/types.tex
author blanchet
Mon, 19 Apr 2010 18:14:45 +0200
changeset 36230 43d10a494c91
parent 31678 752f23a37240
child 48522 708278fc2dff
permissions -rw-r--r--
added warning about inconsistent context to Metis; it makes more sense here than in Sledgehammer, because Sledgehammer is unsound and there's no point in having people panicking about the consistency of their context when their context is in fact consistent
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10305
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
     1
\chapter{More about Types}
10539
5929460a41df *** empty log message ***
nipkow
parents: 10538
diff changeset
     2
\label{ch:more-types}
10305
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
     3
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
     4
So far we have learned about a few basic types (for example \isa{bool} and
11277
a2bff98d6e5d *** empty log message ***
nipkow
parents: 11213
diff changeset
     5
\isa{nat}), type abbreviations (\isacommand{types}) and recursive datatypes
10885
90695f46440b lcp's pass over the book, chapters 1-8
paulson
parents: 10595
diff changeset
     6
(\isacommand{datatype}). This chapter will introduce more
10305
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
     7
advanced material:
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
     8
\begin{itemize}
31678
752f23a37240 reworked section on type classes
haftmann
parents: 25257
diff changeset
     9
\item Pairs ({\S}\ref{sec:products}) and records ({\S}\ref{sec:records}),
752f23a37240 reworked section on type classes
haftmann
parents: 25257
diff changeset
    10
and how to reason about them.
11149
e258b536a137 *** empty log message ***
nipkow
parents: 10885
diff changeset
    11
\item Type classes: how to specify and reason about axiomatic collections of
14400
6069098854b9 new numerics section using type classes
paulson
parents: 12568
diff changeset
    12
  types ({\S}\ref{sec:axclass}). This section leads on to a discussion of
6069098854b9 new numerics section using type classes
paulson
parents: 12568
diff changeset
    13
  Isabelle's numeric types ({\S}\ref{sec:numbers}).  
6069098854b9 new numerics section using type classes
paulson
parents: 12568
diff changeset
    14
\item Introducing your own types: how to define types that
10538
d1bf9ca9008d *** empty log message ***
nipkow
parents: 10420
diff changeset
    15
  cannot be constructed with any of the basic methods
d1bf9ca9008d *** empty log message ***
nipkow
parents: 10420
diff changeset
    16
  ({\S}\ref{sec:adv-typedef}).
10305
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    17
\end{itemize}
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    18
31678
752f23a37240 reworked section on type classes
haftmann
parents: 25257
diff changeset
    19
The material in this section goes beyond the needs of most novices.
752f23a37240 reworked section on type classes
haftmann
parents: 25257
diff changeset
    20
Serious users should at least skim the sections as far as type classes.
752f23a37240 reworked section on type classes
haftmann
parents: 25257
diff changeset
    21
That material is fairly advanced; read the beginning to understand what it
752f23a37240 reworked section on type classes
haftmann
parents: 25257
diff changeset
    22
is about, but consult the rest only when necessary.
10595
be043b89acc5 partial numerics section
paulson
parents: 10543
diff changeset
    23
11428
332347b9b942 tidying the index
paulson
parents: 11389
diff changeset
    24
\index{pairs and tuples|(}
14400
6069098854b9 new numerics section using type classes
paulson
parents: 12568
diff changeset
    25
\input{Types/document/Pairs}    %%%Section "Pairs and Tuples"
11428
332347b9b942 tidying the index
paulson
parents: 11389
diff changeset
    26
\index{pairs and tuples|)}
10396
5ab08609e6c8 *** empty log message ***
nipkow
parents: 10362
diff changeset
    27
14400
6069098854b9 new numerics section using type classes
paulson
parents: 12568
diff changeset
    28
\input{Types/document/Records}  %%%Section "Records"
11389
55e2aef8909b the records section
paulson
parents: 11277
diff changeset
    29
10396
5ab08609e6c8 *** empty log message ***
nipkow
parents: 10362
diff changeset
    30
31678
752f23a37240 reworked section on type classes
haftmann
parents: 25257
diff changeset
    31
\section{Type Classes} %%%Section
10305
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    32
\label{sec:axclass}
11428
332347b9b942 tidying the index
paulson
parents: 11389
diff changeset
    33
\index{axiomatic type classes|(}
10305
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    34
\index{*axclass|(}
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    35
31678
752f23a37240 reworked section on type classes
haftmann
parents: 25257
diff changeset
    36
The programming language Haskell has popularized the notion of type
752f23a37240 reworked section on type classes
haftmann
parents: 25257
diff changeset
    37
classes: a type class is a set of types with a
752f23a37240 reworked section on type classes
haftmann
parents: 25257
diff changeset
    38
common interface: all types in that class must provide the functions
752f23a37240 reworked section on type classes
haftmann
parents: 25257
diff changeset
    39
in the interface.  Isabelle offers a similar type class concept: in
752f23a37240 reworked section on type classes
haftmann
parents: 25257
diff changeset
    40
addition, properties (\emph{class axioms}) can be specified which any
752f23a37240 reworked section on type classes
haftmann
parents: 25257
diff changeset
    41
instance of this type class must obey.  Thus we can talk about a type
752f23a37240 reworked section on type classes
haftmann
parents: 25257
diff changeset
    42
$\tau$ being in a class $C$, which is written $\tau :: C$.  This is the case
752f23a37240 reworked section on type classes
haftmann
parents: 25257
diff changeset
    43
if $\tau$ satisfies the axioms of $C$. Furthermore, type classes can be
752f23a37240 reworked section on type classes
haftmann
parents: 25257
diff changeset
    44
organized in a hierarchy.  Thus there is the notion of a class $D$
752f23a37240 reworked section on type classes
haftmann
parents: 25257
diff changeset
    45
being a subclass\index{subclasses} of a class $C$, written $D
752f23a37240 reworked section on type classes
haftmann
parents: 25257
diff changeset
    46
< C$. This is the case if all axioms of $C$ are also provable in $D$.
10305
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    47
31678
752f23a37240 reworked section on type classes
haftmann
parents: 25257
diff changeset
    48
In this section we introduce the most important concepts behind type
752f23a37240 reworked section on type classes
haftmann
parents: 25257
diff changeset
    49
classes by means of a running example from algebra.  This should give
752f23a37240 reworked section on type classes
haftmann
parents: 25257
diff changeset
    50
you an intuition how to use type classes and to understand
752f23a37240 reworked section on type classes
haftmann
parents: 25257
diff changeset
    51
specifications involving type classes.  Type classes are covered more
752f23a37240 reworked section on type classes
haftmann
parents: 25257
diff changeset
    52
deeply in a separate tutorial \cite{isabelle-classes}.
25257
8faf184ba5b1 *** empty log message ***
nipkow
parents: 14400
diff changeset
    53
10305
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    54
\subsection{Overloading}
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    55
\label{sec:overloading}
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    56
\index{overloading|(}
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    57
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    58
\input{Types/document/Overloading}
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    59
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    60
\index{overloading|)}
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    61
10362
c6b197ccf1f1 *** empty log message ***
nipkow
parents: 10329
diff changeset
    62
\input{Types/document/Axioms}
10305
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    63
31678
752f23a37240 reworked section on type classes
haftmann
parents: 25257
diff changeset
    64
\index{type classes|)}
752f23a37240 reworked section on type classes
haftmann
parents: 25257
diff changeset
    65
\index{*class|)}
11149
e258b536a137 *** empty log message ***
nipkow
parents: 10885
diff changeset
    66
14400
6069098854b9 new numerics section using type classes
paulson
parents: 12568
diff changeset
    67
\input{Types/numerics}             %%%Section "Numbers"
11149
e258b536a137 *** empty log message ***
nipkow
parents: 10885
diff changeset
    68
14400
6069098854b9 new numerics section using type classes
paulson
parents: 12568
diff changeset
    69
\input{Types/document/Typedefs}    %%%Section "Introducing New Types"