1 % |
|
2 \begin{isabellebody}% |
|
3 \def\isabellecontext{Product}% |
|
4 % |
|
5 \isamarkupheader{Syntactic classes% |
|
6 } |
|
7 \isamarkuptrue% |
|
8 % |
|
9 \isadelimtheory |
|
10 % |
|
11 \endisadelimtheory |
|
12 % |
|
13 \isatagtheory |
|
14 \isacommand{theory}\isamarkupfalse% |
|
15 \ Product\ \isakeyword{imports}\ Main\ \isakeyword{begin}% |
|
16 \endisatagtheory |
|
17 {\isafoldtheory}% |
|
18 % |
|
19 \isadelimtheory |
|
20 % |
|
21 \endisadelimtheory |
|
22 % |
|
23 \begin{isamarkuptext}% |
|
24 \medskip\noindent There is still a feature of Isabelle's type system |
|
25 left that we have not yet discussed. When declaring polymorphic |
|
26 constants \isa{c\ {\isasymColon}\ {\isasymsigma}}, the type variables occurring in \isa{{\isasymsigma}} |
|
27 may be constrained by type classes (or even general sorts) in an |
|
28 arbitrary way. Note that by default, in Isabelle/HOL the |
|
29 declaration \isa{{\isasymodot}\ {\isasymColon}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a} is actually an abbreviation |
|
30 for \isa{{\isasymodot}\ {\isasymColon}\ {\isacharprime}a{\isasymColon}type\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a} Since class \isa{type} is the |
|
31 universal class of HOL, this is not really a constraint at all. |
|
32 |
|
33 The \isa{product} class below provides a less degenerate example of |
|
34 syntactic type classes.% |
|
35 \end{isamarkuptext}% |
|
36 \isamarkuptrue% |
|
37 \isacommand{axclass}\isamarkupfalse% |
|
38 \isanewline |
|
39 \ \ product\ {\isasymsubseteq}\ type\isanewline |
|
40 \isacommand{consts}\isamarkupfalse% |
|
41 \isanewline |
|
42 \ \ product\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a{\isasymColon}product\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a{\isachardoublequoteclose}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequoteopen}{\isasymodot}{\isachardoublequoteclose}\ {\isadigit{7}}{\isadigit{0}}{\isacharparenright}% |
|
43 \begin{isamarkuptext}% |
|
44 Here class \isa{product} is defined as subclass of \isa{type} |
|
45 without any additional axioms. This effects in logical equivalence |
|
46 of \isa{product} and \isa{type}, as is reflected by the trivial |
|
47 introduction rule generated for this definition. |
|
48 |
|
49 \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 |
|
50 from the logic's point of view. It even makes the most sense to |
|
51 remove sort constraints from constant declarations, as far as the |
|
52 purely logical meaning is concerned \cite{Wenzel:1997:TPHOL}. |
|
53 |
|
54 On the other hand there are syntactic differences, of course. |
|
55 Constants \isa{{\isasymodot}} on some type \isa{{\isasymtau}} are rejected by the |
|
56 type-checker, unless the arity \isa{{\isasymtau}\ {\isasymColon}\ product} is part of the |
|
57 type signature. In our example, this arity may be always added when |
|
58 required by means of an \isakeyword{instance} with the default proof |
|
59 (double-dot). |
|
60 |
|
61 \medskip Thus, we may observe the following discipline of using |
|
62 syntactic classes. Overloaded polymorphic constants have their type |
|
63 arguments restricted to an associated (logically trivial) class |
|
64 \isa{c}. Only immediately before \emph{specifying} these |
|
65 constants on a certain type \isa{{\isasymtau}} do we instantiate \isa{{\isasymtau}\ {\isasymColon}\ c}. |
|
66 |
|
67 This is done for class \isa{product} and type \isa{bool} as |
|
68 follows.% |
|
69 \end{isamarkuptext}% |
|
70 \isamarkuptrue% |
|
71 \isacommand{instance}\isamarkupfalse% |
|
72 \ bool\ {\isacharcolon}{\isacharcolon}\ product% |
|
73 \isadelimproof |
|
74 \ % |
|
75 \endisadelimproof |
|
76 % |
|
77 \isatagproof |
|
78 \isacommand{{\isachardot}{\isachardot}}\isamarkupfalse% |
|
79 % |
|
80 \endisatagproof |
|
81 {\isafoldproof}% |
|
82 % |
|
83 \isadelimproof |
|
84 % |
|
85 \endisadelimproof |
|
86 \isanewline |
|
87 \isacommand{defs}\isamarkupfalse% |
|
88 \ {\isacharparenleft}\isakeyword{overloaded}{\isacharparenright}\isanewline |
|
89 \ \ product{\isacharunderscore}bool{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequoteopen}x\ {\isasymodot}\ y\ {\isasymequiv}\ x\ {\isasymand}\ y{\isachardoublequoteclose}% |
|
90 \begin{isamarkuptext}% |
|
91 The definition \isa{prod{\isacharunderscore}bool{\isacharunderscore}def} becomes syntactically |
|
92 well-formed only after the arity \isa{bool\ {\isasymColon}\ product} is made |
|
93 known to the type checker. |
|
94 |
|
95 \medskip It is very important to see that above \isakeyword{defs} are |
|
96 not directly connected with \isakeyword{instance} at all! We were |
|
97 just following our convention to specify \isa{{\isasymodot}} on \isa{bool} |
|
98 after having instantiated \isa{bool\ {\isasymColon}\ product}. Isabelle does |
|
99 not require these definitions, which is in contrast to programming |
|
100 languages like Haskell \cite{haskell-report}. |
|
101 |
|
102 \medskip While Isabelle type classes and those of Haskell are almost |
|
103 the same as far as type-checking and type inference are concerned, |
|
104 there are important semantic differences. Haskell classes require |
|
105 their instances to \emph{provide operations} of certain \emph{names}. |
|
106 Therefore, its \texttt{instance} has a \texttt{where} part that tells |
|
107 the system what these ``member functions'' should be. |
|
108 |
|
109 This style of \texttt{instance} would not make much sense in |
|
110 Isabelle's meta-logic, because there is no internal notion of |
|
111 ``providing operations'' or even ``names of functions''.% |
|
112 \end{isamarkuptext}% |
|
113 \isamarkuptrue% |
|
114 % |
|
115 \isadelimtheory |
|
116 % |
|
117 \endisadelimtheory |
|
118 % |
|
119 \isatagtheory |
|
120 \isacommand{end}\isamarkupfalse% |
|
121 % |
|
122 \endisatagtheory |
|
123 {\isafoldtheory}% |
|
124 % |
|
125 \isadelimtheory |
|
126 % |
|
127 \endisadelimtheory |
|
128 \isanewline |
|
129 \end{isabellebody}% |
|
130 %%% Local Variables: |
|
131 %%% mode: latex |
|
132 %%% TeX-master: "root" |
|
133 %%% End: |
|