author | paulson |
Tue, 01 Feb 2005 18:01:57 +0100 | |
changeset 15481 | fc075ae929e4 |
parent 13778 | 61272514e3b5 |
child 16353 | 94e565ded526 |
permissions | -rw-r--r-- |
10305 | 1 |
% |
2 |
\begin{isabellebody}% |
|
3 |
\def\isabellecontext{Overloading{\isadigit{1}}}% |
|
11866 | 4 |
\isamarkupfalse% |
10305 | 5 |
% |
10878 | 6 |
\isamarkupsubsubsection{Controlled Overloading with Type Classes% |
10397 | 7 |
} |
11866 | 8 |
\isamarkuptrue% |
10305 | 9 |
% |
10 |
\begin{isamarkuptext}% |
|
11494 | 11 |
We now start with the theory of ordering relations, which we shall phrase |
11277 | 12 |
in terms of the two binary symbols \isa{{\isacharless}{\isacharless}} and \isa{{\isacharless}{\isacharless}{\isacharequal}} |
12815 | 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 | 14 |
introduce the class \isa{ordrel}:% |
15 |
\end{isamarkuptext}% |
|
11866 | 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 | 18 |
% |
10305 | 19 |
\begin{isamarkuptext}% |
20 |
\noindent |
|
10328 | 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 | 24 |
This is a degenerate form of axiomatic type class without any axioms. |
25 |
Its sole purpose is to restrict the use of overloaded constants to meaningful |
|
26 |
instances:% |
|
27 |
\end{isamarkuptext}% |
|
11866 | 28 |
\isamarkuptrue% |
10328 | 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 | 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% |
31 |
% |
|
10328 | 32 |
\begin{isamarkuptext}% |
33 |
\noindent |
|
10396 | 34 |
Note that only one occurrence of a type variable in a type needs to be |
35 |
constrained with a class; the constraint is propagated to the other |
|
36 |
occurrences automatically. |
|
37 |
||
11494 | 38 |
So far there are no types of class \isa{ordrel}. To breathe life |
10328 | 39 |
into \isa{ordrel} we need to declare a type to be an \bfindex{instance} of |
40 |
\isa{ordrel}:% |
|
41 |
\end{isamarkuptext}% |
|
11866 | 42 |
\isamarkuptrue% |
43 |
\isacommand{instance}\ bool\ {\isacharcolon}{\isacharcolon}\ ordrel\isamarkupfalse% |
|
44 |
\isamarkuptrue% |
|
15481 | 45 |
\isamarkupfalse% |
11866 | 46 |
% |
10328 | 47 |
\begin{isamarkuptext}% |
48 |
\noindent |
|
49 |
More interesting \isacommand{instance} proofs will arise below |
|
50 |
in the context of proper axiomatic type classes. |
|
51 |
||
11161 | 52 |
Although terms like \isa{False\ {\isacharless}{\isacharless}{\isacharequal}\ P} are now legal, we still need to say |
10328 | 53 |
what the relation symbols actually mean at type \isa{bool}:% |
54 |
\end{isamarkuptext}% |
|
11866 | 55 |
\isamarkuptrue% |
10305 | 56 |
\isacommand{defs}\ {\isacharparenleft}\isakeyword{overloaded}{\isacharparenright}\isanewline |
57 |
le{\isacharunderscore}bool{\isacharunderscore}def{\isacharcolon}\ \ {\isachardoublequote}P\ {\isacharless}{\isacharless}{\isacharequal}\ Q\ {\isasymequiv}\ P\ {\isasymlongrightarrow}\ Q{\isachardoublequote}\isanewline |
|
11866 | 58 |
less{\isacharunderscore}bool{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequote}P\ {\isacharless}{\isacharless}\ Q\ {\isasymequiv}\ {\isasymnot}P\ {\isasymand}\ Q{\isachardoublequote}\isamarkupfalse% |
59 |
% |
|
10305 | 60 |
\begin{isamarkuptext}% |
10328 | 61 |
\noindent |
11494 | 62 |
Now \isa{False\ {\isacharless}{\isacharless}{\isacharequal}\ P} is provable:% |
10305 | 63 |
\end{isamarkuptext}% |
11866 | 64 |
\isamarkuptrue% |
10328 | 65 |
\isacommand{lemma}\ {\isachardoublequote}False\ {\isacharless}{\isacharless}{\isacharequal}\ P{\isachardoublequote}\isanewline |
11866 | 66 |
\isamarkupfalse% |
15481 | 67 |
\isamarkupfalse% |
11866 | 68 |
% |
10305 | 69 |
\begin{isamarkuptext}% |
70 |
\noindent |
|
11494 | 71 |
At this point, \isa{{\isacharbrackleft}{\isacharbrackright}\ {\isacharless}{\isacharless}{\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}} is not even well-typed. |
72 |
To make it well-typed, |
|
10305 | 73 |
we need to make lists a type of class \isa{ordrel}:% |
74 |
\end{isamarkuptext}% |
|
11866 | 75 |
\isamarkuptrue% |
76 |
\isamarkupfalse% |
|
10305 | 77 |
\end{isabellebody}% |
78 |
%%% Local Variables: |
|
79 |
%%% mode: latex |
|
80 |
%%% TeX-master: "root" |
|
81 |
%%% End: |