doc-src/TutorialI/Types/document/Overloading1.tex
author paulson
Tue, 01 Feb 2005 18:01:57 +0100
changeset 15481 fc075ae929e4
parent 13778 61272514e3b5
child 16353 94e565ded526
permissions -rw-r--r--
the new subst tactic, by Lucas Dixon
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10305
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
     1
%
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
     2
\begin{isabellebody}%
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
     3
\def\isabellecontext{Overloading{\isadigit{1}}}%
11866
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
     4
\isamarkupfalse%
10305
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
     5
%
10878
b254d5ad6dd4 auto update
paulson
parents: 10397
diff changeset
     6
\isamarkupsubsubsection{Controlled Overloading with Type Classes%
10397
e2d0dda41f2c auto update
paulson
parents: 10396
diff changeset
     7
}
11866
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
     8
\isamarkuptrue%
10305
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
     9
%
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    10
\begin{isamarkuptext}%
11494
23a118849801 revisions and indexing
paulson
parents: 11310
diff changeset
    11
We now start with the theory of ordering relations, which we shall phrase
11277
a2bff98d6e5d *** empty log message ***
nipkow
parents: 11161
diff changeset
    12
in terms of the two binary symbols \isa{{\isacharless}{\isacharless}} and \isa{{\isacharless}{\isacharless}{\isacharequal}}
12815
wenzelm
parents: 12338
diff changeset
    13
to avoid clashes with \isa{{\isacharless}} and \isa{{\isacharless}{\isacharequal}} in theory \isa{Main}. To restrict the application of \isa{{\isacharless}{\isacharless}} and \isa{{\isacharless}{\isacharless}{\isacharequal}} we
10305
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    14
introduce the class \isa{ordrel}:%
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    15
\end{isamarkuptext}%
11866
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
    16
\isamarkuptrue%
12338
de0f4a63baa5 renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents: 11866
diff changeset
    17
\isacommand{axclass}\ ordrel\ {\isacharless}\ type\isamarkupfalse%
11866
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
    18
%
10305
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    19
\begin{isamarkuptext}%
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    20
\noindent
10328
bf33cbd76c05 *** empty log message ***
nipkow
parents: 10305
diff changeset
    21
This introduces a new class \isa{ordrel} and makes it a subclass of
12338
de0f4a63baa5 renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents: 11866
diff changeset
    22
the predefined class \isa{type}, which
de0f4a63baa5 renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents: 11866
diff changeset
    23
is the class of all HOL types.
10305
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    24
This is a degenerate form of axiomatic type class without any axioms.
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    25
Its sole purpose is to restrict the use of overloaded constants to meaningful
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    26
instances:%
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    27
\end{isamarkuptext}%
11866
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
    28
\isamarkuptrue%
10328
bf33cbd76c05 *** empty log message ***
nipkow
parents: 10305
diff changeset
    29
\isacommand{consts}\ less\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}{\isacharprime}a{\isacharcolon}{\isacharcolon}ordrel{\isacharparenright}\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ bool{\isachardoublequote}\ \ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequote}{\isacharless}{\isacharless}{\isachardoublequote}\ \ {\isadigit{5}}{\isadigit{0}}{\isacharparenright}\isanewline
11866
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
    30
\ \ \ \ \ \ \ le\ \ \ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}{\isacharprime}a{\isacharcolon}{\isacharcolon}ordrel{\isacharparenright}\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ bool{\isachardoublequote}\ \ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequote}{\isacharless}{\isacharless}{\isacharequal}{\isachardoublequote}\ {\isadigit{5}}{\isadigit{0}}{\isacharparenright}\isamarkupfalse%
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
    31
%
10328
bf33cbd76c05 *** empty log message ***
nipkow
parents: 10305
diff changeset
    32
\begin{isamarkuptext}%
bf33cbd76c05 *** empty log message ***
nipkow
parents: 10305
diff changeset
    33
\noindent
10396
5ab08609e6c8 *** empty log message ***
nipkow
parents: 10395
diff changeset
    34
Note that only one occurrence of a type variable in a type needs to be
5ab08609e6c8 *** empty log message ***
nipkow
parents: 10395
diff changeset
    35
constrained with a class; the constraint is propagated to the other
5ab08609e6c8 *** empty log message ***
nipkow
parents: 10395
diff changeset
    36
occurrences automatically.
5ab08609e6c8 *** empty log message ***
nipkow
parents: 10395
diff changeset
    37
11494
23a118849801 revisions and indexing
paulson
parents: 11310
diff changeset
    38
So far there are no types of class \isa{ordrel}. To breathe life
10328
bf33cbd76c05 *** empty log message ***
nipkow
parents: 10305
diff changeset
    39
into \isa{ordrel} we need to declare a type to be an \bfindex{instance} of
bf33cbd76c05 *** empty log message ***
nipkow
parents: 10305
diff changeset
    40
\isa{ordrel}:%
bf33cbd76c05 *** empty log message ***
nipkow
parents: 10305
diff changeset
    41
\end{isamarkuptext}%
11866
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
    42
\isamarkuptrue%
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
    43
\isacommand{instance}\ bool\ {\isacharcolon}{\isacharcolon}\ ordrel\isamarkupfalse%
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
    44
\isamarkuptrue%
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 13778
diff changeset
    45
\isamarkupfalse%
11866
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
    46
%
10328
bf33cbd76c05 *** empty log message ***
nipkow
parents: 10305
diff changeset
    47
\begin{isamarkuptext}%
bf33cbd76c05 *** empty log message ***
nipkow
parents: 10305
diff changeset
    48
\noindent
bf33cbd76c05 *** empty log message ***
nipkow
parents: 10305
diff changeset
    49
More interesting \isacommand{instance} proofs will arise below
bf33cbd76c05 *** empty log message ***
nipkow
parents: 10305
diff changeset
    50
in the context of proper axiomatic type classes.
bf33cbd76c05 *** empty log message ***
nipkow
parents: 10305
diff changeset
    51
11161
166f7d87b37f *** empty log message ***
nipkow
parents: 10878
diff changeset
    52
Although terms like \isa{False\ {\isacharless}{\isacharless}{\isacharequal}\ P} are now legal, we still need to say
10328
bf33cbd76c05 *** empty log message ***
nipkow
parents: 10305
diff changeset
    53
what the relation symbols actually mean at type \isa{bool}:%
bf33cbd76c05 *** empty log message ***
nipkow
parents: 10305
diff changeset
    54
\end{isamarkuptext}%
11866
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
    55
\isamarkuptrue%
10305
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    56
\isacommand{defs}\ {\isacharparenleft}\isakeyword{overloaded}{\isacharparenright}\isanewline
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    57
le{\isacharunderscore}bool{\isacharunderscore}def{\isacharcolon}\ \ {\isachardoublequote}P\ {\isacharless}{\isacharless}{\isacharequal}\ Q\ {\isasymequiv}\ P\ {\isasymlongrightarrow}\ Q{\isachardoublequote}\isanewline
11866
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
    58
less{\isacharunderscore}bool{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequote}P\ {\isacharless}{\isacharless}\ Q\ {\isasymequiv}\ {\isasymnot}P\ {\isasymand}\ Q{\isachardoublequote}\isamarkupfalse%
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
    59
%
10305
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    60
\begin{isamarkuptext}%
10328
bf33cbd76c05 *** empty log message ***
nipkow
parents: 10305
diff changeset
    61
\noindent
11494
23a118849801 revisions and indexing
paulson
parents: 11310
diff changeset
    62
Now \isa{False\ {\isacharless}{\isacharless}{\isacharequal}\ P} is provable:%
10305
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    63
\end{isamarkuptext}%
11866
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
    64
\isamarkuptrue%
10328
bf33cbd76c05 *** empty log message ***
nipkow
parents: 10305
diff changeset
    65
\isacommand{lemma}\ {\isachardoublequote}False\ {\isacharless}{\isacharless}{\isacharequal}\ P{\isachardoublequote}\isanewline
11866
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
    66
\isamarkupfalse%
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 13778
diff changeset
    67
\isamarkupfalse%
11866
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
    68
%
10305
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    69
\begin{isamarkuptext}%
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    70
\noindent
11494
23a118849801 revisions and indexing
paulson
parents: 11310
diff changeset
    71
At this point, \isa{{\isacharbrackleft}{\isacharbrackright}\ {\isacharless}{\isacharless}{\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}} is not even well-typed.
23a118849801 revisions and indexing
paulson
parents: 11310
diff changeset
    72
To make it well-typed,
10305
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    73
we need to make lists a type of class \isa{ordrel}:%
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    74
\end{isamarkuptext}%
11866
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
    75
\isamarkuptrue%
fbd097aec213 updated;
wenzelm
parents: 11494
diff changeset
    76
\isamarkupfalse%
10305
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    77
\end{isabellebody}%
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    78
%%% Local Variables:
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    79
%%% mode: latex
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    80
%%% TeX-master: "root"
adff80268127 *** empty log message ***
nipkow
parents:
diff changeset
    81
%%% End: