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