| author | paulson |
| Mon, 02 Feb 2004 12:23:46 +0100 | |
| changeset 14371 | c78c7da09519 |
| parent 12338 | de0f4a63baa5 |
| child 17132 | 153fe83804c9 |
| permissions | -rw-r--r-- |
| 9767 | 1 |
% |
2 |
\begin{isabellebody}%
|
|
| 9921 | 3 |
\def\isabellecontext{Product}%
|
| 8903 | 4 |
% |
| 10395 | 5 |
\isamarkupheader{Syntactic classes%
|
6 |
} |
|
| 11964 | 7 |
\isamarkuptrue% |
8 |
\isacommand{theory}\ Product\ {\isacharequal}\ Main{\isacharcolon}\isamarkupfalse%
|
|
9 |
% |
|
| 8903 | 10 |
\begin{isamarkuptext}%
|
11 |
\medskip\noindent There is still a feature of Isabelle's type system |
|
|
12338
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
12 |
left that we have not yet discussed. When declaring polymorphic |
|
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
13 |
constants \isa{c\ {\isasymColon}\ {\isasymsigma}}, the type variables occurring in \isa{{\isasymsigma}}
|
|
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
14 |
may be constrained by type classes (or even general sorts) in an |
|
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
15 |
arbitrary way. Note that by default, in Isabelle/HOL the |
|
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
16 |
declaration \isa{{\isasymodot}\ {\isasymColon}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a} is actually an abbreviation
|
|
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
17 |
for \isa{{\isasymodot}\ {\isasymColon}\ {\isacharprime}a{\isasymColon}type\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a} Since class \isa{type} is the
|
|
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
18 |
universal class of HOL, this is not really a constraint at all. |
| 8903 | 19 |
|
| 10140 | 20 |
The \isa{product} class below provides a less degenerate example of
|
| 8903 | 21 |
syntactic type classes.% |
22 |
\end{isamarkuptext}%
|
|
| 11964 | 23 |
\isamarkuptrue% |
| 8890 | 24 |
\isacommand{axclass}\isanewline
|
|
12338
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
25 |
\ \ product\ {\isasymsubseteq}\ type\isanewline
|
| 11964 | 26 |
\isamarkupfalse% |
| 8890 | 27 |
\isacommand{consts}\isanewline
|
| 11964 | 28 |
\ \ product\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a{\isasymColon}product\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a{\isachardoublequote}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequote}{\isasymodot}{\isachardoublequote}\ {\isadigit{7}}{\isadigit{0}}{\isacharparenright}\isamarkupfalse%
|
29 |
% |
|
| 8903 | 30 |
\begin{isamarkuptext}%
|
|
12338
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
31 |
Here class \isa{product} is defined as subclass of \isa{type}
|
|
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
32 |
without any additional axioms. This effects in logical equivalence |
|
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
33 |
of \isa{product} and \isa{type}, as is reflected by the trivial
|
|
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
34 |
introduction rule generated for this definition. |
| 8903 | 35 |
|
|
12338
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
36 |
\medskip So what is the difference of declaring \isa{{\isasymodot}\ {\isasymColon}\ {\isacharprime}a{\isasymColon}product\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a} vs.\ declaring \isa{{\isasymodot}\ {\isasymColon}\ {\isacharprime}a{\isasymColon}type\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a} anyway? In this particular case where \isa{product\ {\isasymequiv}\ type}, it should be obvious that both declarations are the same
|
|
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
37 |
from the logic's point of view. It even makes the most sense to |
|
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
38 |
remove sort constraints from constant declarations, as far as the |
|
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
39 |
purely logical meaning is concerned \cite{Wenzel:1997:TPHOL}.
|
| 8903 | 40 |
|
|
12338
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
41 |
On the other hand there are syntactic differences, of course. |
|
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
42 |
Constants \isa{{\isasymodot}} on some type \isa{{\isasymtau}} are rejected by the
|
|
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
43 |
type-checker, unless the arity \isa{{\isasymtau}\ {\isasymColon}\ product} is part of the
|
|
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
44 |
type signature. In our example, this arity may be always added when |
|
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
45 |
required by means of an $\INSTANCE$ with the default proof $\DDOT$. |
| 8903 | 46 |
|
|
12338
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
47 |
\medskip Thus, we may observe the following discipline of using |
|
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
48 |
syntactic classes. Overloaded polymorphic constants have their type |
|
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
49 |
arguments restricted to an associated (logically trivial) class |
|
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
50 |
\isa{c}. Only immediately before \emph{specifying} these
|
|
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
51 |
constants on a certain type \isa{{\isasymtau}} do we instantiate \isa{{\isasymtau}\ {\isasymColon}\ c}.
|
| 8903 | 52 |
|
|
12338
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
53 |
This is done for class \isa{product} and type \isa{bool} as
|
|
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
54 |
follows.% |
| 8903 | 55 |
\end{isamarkuptext}%
|
| 11964 | 56 |
\isamarkuptrue% |
57 |
\isacommand{instance}\ bool\ {\isacharcolon}{\isacharcolon}\ product\ \isamarkupfalse%
|
|
58 |
\isacommand{{\isachardot}{\isachardot}}\isanewline
|
|
59 |
\isamarkupfalse% |
|
| 9665 | 60 |
\isacommand{defs}\ {\isacharparenleft}\isakeyword{overloaded}{\isacharparenright}\isanewline
|
| 11964 | 61 |
\ \ product{\isacharunderscore}bool{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequote}x\ {\isasymodot}\ y\ {\isasymequiv}\ x\ {\isasymand}\ y{\isachardoublequote}\isamarkupfalse%
|
62 |
% |
|
| 8903 | 63 |
\begin{isamarkuptext}%
|
| 10140 | 64 |
The definition \isa{prod{\isacharunderscore}bool{\isacharunderscore}def} becomes syntactically
|
65 |
well-formed only after the arity \isa{bool\ {\isasymColon}\ product} is made
|
|
66 |
known to the type checker. |
|
| 8903 | 67 |
|
68 |
\medskip It is very important to see that above $\DEFS$ are not |
|
| 10223 | 69 |
directly connected with $\INSTANCE$ at all! We were just following |
70 |
our convention to specify \isa{{\isasymodot}} on \isa{bool} after having
|
|
71 |
instantiated \isa{bool\ {\isasymColon}\ product}. Isabelle does not require
|
|
72 |
these definitions, which is in contrast to programming languages like |
|
73 |
Haskell \cite{haskell-report}.
|
|
| 8903 | 74 |
|
75 |
\medskip While Isabelle type classes and those of Haskell are almost |
|
76 |
the same as far as type-checking and type inference are concerned, |
|
| 8907 | 77 |
there are important semantic differences. Haskell classes require |
78 |
their instances to \emph{provide operations} of certain \emph{names}.
|
|
| 8903 | 79 |
Therefore, its \texttt{instance} has a \texttt{where} part that tells
|
80 |
the system what these ``member functions'' should be. |
|
81 |
||
| 10140 | 82 |
This style of \texttt{instance} would not make much sense in
|
83 |
Isabelle's meta-logic, because there is no internal notion of |
|
84 |
``providing operations'' or even ``names of functions''.% |
|
| 8903 | 85 |
\end{isamarkuptext}%
|
| 11964 | 86 |
\isamarkuptrue% |
|
12338
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
87 |
\isacommand{end}\isanewline
|
|
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11964
diff
changeset
|
88 |
\isamarkupfalse% |
| 11964 | 89 |
\end{isabellebody}%
|
| 9145 | 90 |
%%% Local Variables: |
91 |
%%% mode: latex |
|
92 |
%%% TeX-master: "root" |
|
93 |
%%% End: |