author | wenzelm |
Tue, 03 Mar 2009 19:30:43 +0100 | |
changeset 30229 | 9861257b18e6 |
parent 30209 | doc-src/IsarAdvanced/Classes/Thy/document/Classes.tex@9e245d524997 |
parent 30227 | doc-src/IsarAdvanced/Classes/Thy/document/Classes.tex@853abb4853cc |
child 30729 | 461ee3e49ad3 |
permissions | -rw-r--r-- |
20967 | 1 |
% |
2 |
\begin{isabellebody}% |
|
3 |
\def\isabellecontext{Classes}% |
|
4 |
% |
|
5 |
\isadelimtheory |
|
6 |
% |
|
7 |
\endisadelimtheory |
|
8 |
% |
|
9 |
\isatagtheory |
|
28565 | 10 |
\isacommand{theory}\isamarkupfalse% |
11 |
\ Classes\isanewline |
|
12 |
\isakeyword{imports}\ Main\ Setup\isanewline |
|
13 |
\isakeyword{begin}% |
|
20967 | 14 |
\endisatagtheory |
15 |
{\isafoldtheory}% |
|
16 |
% |
|
17 |
\isadelimtheory |
|
18 |
% |
|
19 |
\endisadelimtheory |
|
20 |
% |
|
21 |
\isamarkupsection{Introduction% |
|
22 |
} |
|
23 |
\isamarkuptrue% |
|
24 |
% |
|
25 |
\begin{isamarkuptext}% |
|
22317 | 26 |
Type classes were introduces by Wadler and Blott \cite{wadler89how} |
27 |
into the Haskell language, to allow for a reasonable implementation |
|
28 |
of overloading\footnote{throughout this tutorial, we are referring |
|
29 |
to classical Haskell 1.0 type classes, not considering |
|
30 |
later additions in expressiveness}. |
|
31 |
As a canonical example, a polymorphic equality function |
|
32 |
\isa{eq\ {\isasymColon}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ bool} which is overloaded on different |
|
22550 | 33 |
types for \isa{{\isasymalpha}}, which is achieved by splitting introduction |
22317 | 34 |
of the \isa{eq} function from its overloaded definitions by means |
35 |
of \isa{class} and \isa{instance} declarations: |
|
30227 | 36 |
\footnote{syntax here is a kind of isabellized Haskell} |
22317 | 37 |
|
28565 | 38 |
\begin{quote} |
39 |
||
30227 | 40 |
\noindent\isa{class\ eq\ where} \\ |
28565 | 41 |
\hspace*{2ex}\isa{eq\ {\isasymColon}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ bool} |
22317 | 42 |
|
28565 | 43 |
\medskip\noindent\isa{instance\ nat\ {\isasymColon}\ eq\ where} \\ |
44 |
\hspace*{2ex}\isa{eq\ {\isadigit{0}}\ {\isadigit{0}}\ {\isacharequal}\ True} \\ |
|
45 |
\hspace*{2ex}\isa{eq\ {\isadigit{0}}\ {\isacharunderscore}\ {\isacharequal}\ False} \\ |
|
46 |
\hspace*{2ex}\isa{eq\ {\isacharunderscore}\ {\isadigit{0}}\ {\isacharequal}\ False} \\ |
|
47 |
\hspace*{2ex}\isa{eq\ {\isacharparenleft}Suc\ n{\isacharparenright}\ {\isacharparenleft}Suc\ m{\isacharparenright}\ {\isacharequal}\ eq\ n\ m} |
|
22317 | 48 |
|
28948 | 49 |
\medskip\noindent\isa{instance\ {\isacharparenleft}{\isasymalpha}{\isasymColon}eq{\isacharcomma}\ {\isasymbeta}{\isasymColon}eq{\isacharparenright}\ pair\ {\isasymColon}\ eq\ where} \\ |
28565 | 50 |
\hspace*{2ex}\isa{eq\ {\isacharparenleft}x{\isadigit{1}}{\isacharcomma}\ y{\isadigit{1}}{\isacharparenright}\ {\isacharparenleft}x{\isadigit{2}}{\isacharcomma}\ y{\isadigit{2}}{\isacharparenright}\ {\isacharequal}\ eq\ x{\isadigit{1}}\ x{\isadigit{2}}\ {\isasymand}\ eq\ y{\isadigit{1}}\ y{\isadigit{2}}} |
22317 | 51 |
|
28565 | 52 |
\medskip\noindent\isa{class\ ord\ extends\ eq\ where} \\ |
53 |
\hspace*{2ex}\isa{less{\isacharunderscore}eq\ {\isasymColon}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ bool} \\ |
|
54 |
\hspace*{2ex}\isa{less\ {\isasymColon}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ bool} |
|
22317 | 55 |
|
28565 | 56 |
\end{quote} |
57 |
||
58 |
\noindent Type variables are annotated with (finitely many) classes; |
|
22317 | 59 |
these annotations are assertions that a particular polymorphic type |
60 |
provides definitions for overloaded functions. |
|
61 |
||
62 |
Indeed, type classes not only allow for simple overloading |
|
63 |
but form a generic calculus, an instance of order-sorted |
|
23956 | 64 |
algebra \cite{Nipkow-Prehofer:1993,nipkow-sorts93,Wenzel:1997:TPHOL}. |
20967 | 65 |
|
28540 | 66 |
From a software engeneering point of view, type classes |
67 |
roughly correspond to interfaces in object-oriented languages like Java; |
|
22317 | 68 |
so, it is naturally desirable that type classes do not only |
24991 | 69 |
provide functions (class parameters) but also state specifications |
22317 | 70 |
implementations must obey. For example, the \isa{class\ eq} |
22550 | 71 |
above could be given the following specification, demanding that |
72 |
\isa{class\ eq} is an equivalence relation obeying reflexivity, |
|
73 |
symmetry and transitivity: |
|
22317 | 74 |
|
28565 | 75 |
\begin{quote} |
22317 | 76 |
|
28565 | 77 |
\noindent\isa{class\ eq\ where} \\ |
78 |
\hspace*{2ex}\isa{eq\ {\isasymColon}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ bool} \\ |
|
79 |
\isa{satisfying} \\ |
|
80 |
\hspace*{2ex}\isa{refl{\isacharcolon}\ eq\ x\ x} \\ |
|
81 |
\hspace*{2ex}\isa{sym{\isacharcolon}\ eq\ x\ y\ {\isasymlongleftrightarrow}\ eq\ x\ y} \\ |
|
82 |
\hspace*{2ex}\isa{trans{\isacharcolon}\ eq\ x\ y\ {\isasymand}\ eq\ y\ z\ {\isasymlongrightarrow}\ eq\ x\ z} |
|
83 |
||
84 |
\end{quote} |
|
85 |
||
86 |
\noindent From a theoretic point of view, type classes are lightweight |
|
22479 | 87 |
modules; Haskell type classes may be emulated by |
22317 | 88 |
SML functors \cite{classes_modules}. |
89 |
Isabelle/Isar offers a discipline of type classes which brings |
|
90 |
all those aspects together: |
|
91 |
||
92 |
\begin{enumerate} |
|
25004 | 93 |
\item specifying abstract parameters together with |
22317 | 94 |
corresponding specifications, |
28540 | 95 |
\item instantiating those abstract parameters by a particular |
22317 | 96 |
type |
97 |
\item in connection with a ``less ad-hoc'' approach to overloading, |
|
23956 | 98 |
\item with a direct link to the Isabelle module system |
99 |
(aka locales \cite{kammueller-locales}). |
|
22317 | 100 |
\end{enumerate} |
101 |
||
22550 | 102 |
\noindent Isar type classes also directly support code generation |
103 |
in a Haskell like fashion. |
|
22317 | 104 |
|
105 |
This tutorial demonstrates common elements of structured specifications |
|
106 |
and abstract reasoning with type classes by the algebraic hierarchy of |
|
107 |
semigroups, monoids and groups. Our background theory is that of |
|
23956 | 108 |
Isabelle/HOL \cite{isa-tutorial}, for which some |
22317 | 109 |
familiarity is assumed. |
110 |
||
111 |
Here we merely present the look-and-feel for end users. |
|
112 |
Internally, those are mapped to more primitive Isabelle concepts. |
|
23956 | 113 |
See \cite{Haftmann-Wenzel:2006:classes} for more detail.% |
20967 | 114 |
\end{isamarkuptext}% |
115 |
\isamarkuptrue% |
|
116 |
% |
|
117 |
\isamarkupsection{A simple algebra example \label{sec:example}% |
|
118 |
} |
|
119 |
\isamarkuptrue% |
|
120 |
% |
|
121 |
\isamarkupsubsection{Class definition% |
|
122 |
} |
|
123 |
\isamarkuptrue% |
|
124 |
% |
|
125 |
\begin{isamarkuptext}% |
|
28565 | 126 |
Depending on an arbitrary type \isa{{\isasymalpha}}, class \isa{semigroup} introduces a binary operator \isa{{\isacharparenleft}{\isasymotimes}{\isacharparenright}} that is |
20967 | 127 |
assumed to be associative:% |
128 |
\end{isamarkuptext}% |
|
129 |
\isamarkuptrue% |
|
28565 | 130 |
% |
131 |
\isadelimquote |
|
132 |
% |
|
133 |
\endisadelimquote |
|
134 |
% |
|
135 |
\isatagquote |
|
136 |
\isacommand{class}\isamarkupfalse% |
|
29705 | 137 |
\ semigroup\ {\isacharequal}\isanewline |
28565 | 138 |
\ \ \isakeyword{fixes}\ mult\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequoteopen}{\isasymotimes}{\isachardoublequoteclose}\ {\isadigit{7}}{\isadigit{0}}{\isacharparenright}\isanewline |
139 |
\ \ \isakeyword{assumes}\ assoc{\isacharcolon}\ {\isachardoublequoteopen}{\isacharparenleft}x\ {\isasymotimes}\ y{\isacharparenright}\ {\isasymotimes}\ z\ {\isacharequal}\ x\ {\isasymotimes}\ {\isacharparenleft}y\ {\isasymotimes}\ z{\isacharparenright}{\isachardoublequoteclose}% |
|
140 |
\endisatagquote |
|
141 |
{\isafoldquote}% |
|
142 |
% |
|
143 |
\isadelimquote |
|
144 |
% |
|
145 |
\endisadelimquote |
|
146 |
% |
|
20967 | 147 |
\begin{isamarkuptext}% |
28565 | 148 |
\noindent This \hyperlink{command.class}{\mbox{\isa{\isacommand{class}}}} specification consists of two |
149 |
parts: the \qn{operational} part names the class parameter |
|
150 |
(\hyperlink{element.fixes}{\mbox{\isa{\isakeyword{fixes}}}}), the \qn{logical} part specifies properties on them |
|
151 |
(\hyperlink{element.assumes}{\mbox{\isa{\isakeyword{assumes}}}}). The local \hyperlink{element.fixes}{\mbox{\isa{\isakeyword{fixes}}}} and |
|
152 |
\hyperlink{element.assumes}{\mbox{\isa{\isakeyword{assumes}}}} are lifted to the theory toplevel, |
|
153 |
yielding the global |
|
24991 | 154 |
parameter \isa{{\isachardoublequote}mult\ {\isasymColon}\ {\isasymalpha}{\isasymColon}semigroup\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequote}} and the |
28565 | 155 |
global theorem \hyperlink{fact.semigroup.assoc:}{\mbox{\isa{semigroup{\isachardot}assoc{\isacharcolon}}}}~\isa{{\isachardoublequote}{\isasymAnd}x\ y\ z\ {\isasymColon}\ {\isasymalpha}{\isasymColon}semigroup{\isachardot}\ {\isacharparenleft}x\ {\isasymotimes}\ y{\isacharparenright}\ {\isasymotimes}\ z\ {\isacharequal}\ x\ {\isasymotimes}\ {\isacharparenleft}y\ {\isasymotimes}\ z{\isacharparenright}{\isachardoublequote}}.% |
20967 | 156 |
\end{isamarkuptext}% |
157 |
\isamarkuptrue% |
|
158 |
% |
|
159 |
\isamarkupsubsection{Class instantiation \label{sec:class_inst}% |
|
160 |
} |
|
161 |
\isamarkuptrue% |
|
162 |
% |
|
163 |
\begin{isamarkuptext}% |
|
164 |
The concrete type \isa{int} is made a \isa{semigroup} |
|
24991 | 165 |
instance by providing a suitable definition for the class parameter |
28565 | 166 |
\isa{{\isacharparenleft}{\isasymotimes}{\isacharparenright}} and a proof for the specification of \hyperlink{fact.assoc}{\mbox{\isa{assoc}}}. |
167 |
This is accomplished by the \hyperlink{command.instantiation}{\mbox{\isa{\isacommand{instantiation}}}} target:% |
|
20967 | 168 |
\end{isamarkuptext}% |
169 |
\isamarkuptrue% |
|
28565 | 170 |
% |
171 |
\isadelimquote |
|
172 |
% |
|
173 |
\endisadelimquote |
|
174 |
% |
|
175 |
\isatagquote |
|
176 |
\isacommand{instantiation}\isamarkupfalse% |
|
20967 | 177 |
\ int\ {\isacharcolon}{\isacharcolon}\ semigroup\isanewline |
28565 | 178 |
\isakeyword{begin}\isanewline |
25533 | 179 |
\isanewline |
28565 | 180 |
\isacommand{definition}\isamarkupfalse% |
181 |
\isanewline |
|
182 |
\ \ mult{\isacharunderscore}int{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequoteopen}i\ {\isasymotimes}\ j\ {\isacharequal}\ i\ {\isacharplus}\ {\isacharparenleft}j{\isasymColon}int{\isacharparenright}{\isachardoublequoteclose}\isanewline |
|
20967 | 183 |
\isanewline |
28565 | 184 |
\isacommand{instance}\isamarkupfalse% |
185 |
\ \isacommand{proof}\isamarkupfalse% |
|
186 |
\isanewline |
|
187 |
\ \ \isacommand{fix}\isamarkupfalse% |
|
20967 | 188 |
\ i\ j\ k\ {\isacharcolon}{\isacharcolon}\ int\ \isacommand{have}\isamarkupfalse% |
189 |
\ {\isachardoublequoteopen}{\isacharparenleft}i\ {\isacharplus}\ j{\isacharparenright}\ {\isacharplus}\ k\ {\isacharequal}\ i\ {\isacharplus}\ {\isacharparenleft}j\ {\isacharplus}\ k{\isacharparenright}{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse% |
|
190 |
\ simp\isanewline |
|
28565 | 191 |
\ \ \isacommand{then}\isamarkupfalse% |
20967 | 192 |
\ \isacommand{show}\isamarkupfalse% |
25247 | 193 |
\ {\isachardoublequoteopen}{\isacharparenleft}i\ {\isasymotimes}\ j{\isacharparenright}\ {\isasymotimes}\ k\ {\isacharequal}\ i\ {\isasymotimes}\ {\isacharparenleft}j\ {\isasymotimes}\ k{\isacharparenright}{\isachardoublequoteclose}\isanewline |
28566 | 194 |
\ \ \ \ \isacommand{unfolding}\isamarkupfalse% |
20967 | 195 |
\ mult{\isacharunderscore}int{\isacharunderscore}def\ \isacommand{{\isachardot}}\isamarkupfalse% |
196 |
\isanewline |
|
28565 | 197 |
\isacommand{qed}\isamarkupfalse% |
25533 | 198 |
\isanewline |
199 |
\isanewline |
|
28565 | 200 |
\isacommand{end}\isamarkupfalse% |
201 |
% |
|
202 |
\endisatagquote |
|
203 |
{\isafoldquote}% |
|
204 |
% |
|
205 |
\isadelimquote |
|
206 |
% |
|
207 |
\endisadelimquote |
|
20967 | 208 |
% |
209 |
\begin{isamarkuptext}% |
|
28565 | 210 |
\noindent \hyperlink{command.instantiation}{\mbox{\isa{\isacommand{instantiation}}}} allows to define class parameters |
25533 | 211 |
at a particular instance using common specification tools (here, |
28565 | 212 |
\hyperlink{command.definition}{\mbox{\isa{\isacommand{definition}}}}). The concluding \hyperlink{command.instance}{\mbox{\isa{\isacommand{instance}}}} |
25533 | 213 |
opens a proof that the given parameters actually conform |
214 |
to the class specification. Note that the first proof step |
|
28565 | 215 |
is the \hyperlink{method.default}{\mbox{\isa{default}}} method, |
216 |
which for such instance proofs maps to the \hyperlink{method.intro-classes}{\mbox{\isa{intro{\isacharunderscore}classes}}} method. |
|
25533 | 217 |
This boils down an instance judgement to the relevant primitive |
22317 | 218 |
proof goals and should conveniently always be the first method applied |
219 |
in an instantiation proof. |
|
220 |
||
25533 | 221 |
From now on, the type-checker will consider \isa{int} |
222 |
as a \isa{semigroup} automatically, i.e.\ any general results |
|
223 |
are immediately available on concrete instances. |
|
28565 | 224 |
|
22550 | 225 |
\medskip Another instance of \isa{semigroup} are the natural numbers:% |
20967 | 226 |
\end{isamarkuptext}% |
227 |
\isamarkuptrue% |
|
228 |
% |
|
28565 | 229 |
\isadelimquote |
230 |
% |
|
231 |
\endisadelimquote |
|
20967 | 232 |
% |
28565 | 233 |
\isatagquote |
234 |
\isacommand{instantiation}\isamarkupfalse% |
|
235 |
\ nat\ {\isacharcolon}{\isacharcolon}\ semigroup\isanewline |
|
236 |
\isakeyword{begin}\isanewline |
|
20967 | 237 |
\isanewline |
28565 | 238 |
\isacommand{primrec}\isamarkupfalse% |
239 |
\ mult{\isacharunderscore}nat\ \isakeyword{where}\isanewline |
|
240 |
\ \ {\isachardoublequoteopen}{\isacharparenleft}{\isadigit{0}}{\isasymColon}nat{\isacharparenright}\ {\isasymotimes}\ n\ {\isacharequal}\ n{\isachardoublequoteclose}\isanewline |
|
241 |
\ \ {\isacharbar}\ {\isachardoublequoteopen}Suc\ m\ {\isasymotimes}\ n\ {\isacharequal}\ Suc\ {\isacharparenleft}m\ {\isasymotimes}\ n{\isacharparenright}{\isachardoublequoteclose}\isanewline |
|
242 |
\isanewline |
|
243 |
\isacommand{instance}\isamarkupfalse% |
|
244 |
\ \isacommand{proof}\isamarkupfalse% |
|
245 |
\isanewline |
|
246 |
\ \ \isacommand{fix}\isamarkupfalse% |
|
20967 | 247 |
\ m\ n\ q\ {\isacharcolon}{\isacharcolon}\ nat\ \isanewline |
28565 | 248 |
\ \ \isacommand{show}\isamarkupfalse% |
25247 | 249 |
\ {\isachardoublequoteopen}m\ {\isasymotimes}\ n\ {\isasymotimes}\ q\ {\isacharequal}\ m\ {\isasymotimes}\ {\isacharparenleft}n\ {\isasymotimes}\ q{\isacharparenright}{\isachardoublequoteclose}\isanewline |
28565 | 250 |
\ \ \ \ \isacommand{by}\isamarkupfalse% |
25871 | 251 |
\ {\isacharparenleft}induct\ m{\isacharparenright}\ auto\isanewline |
28565 | 252 |
\isacommand{qed}\isamarkupfalse% |
25533 | 253 |
\isanewline |
254 |
\isanewline |
|
28565 | 255 |
\isacommand{end}\isamarkupfalse% |
256 |
% |
|
257 |
\endisatagquote |
|
258 |
{\isafoldquote}% |
|
259 |
% |
|
260 |
\isadelimquote |
|
261 |
% |
|
262 |
\endisadelimquote |
|
20967 | 263 |
% |
25871 | 264 |
\begin{isamarkuptext}% |
265 |
\noindent Note the occurence of the name \isa{mult{\isacharunderscore}nat} |
|
266 |
in the primrec declaration; by default, the local name of |
|
267 |
a class operation \isa{f} to instantiate on type constructor |
|
268 |
\isa{{\isasymkappa}} are mangled as \isa{f{\isacharunderscore}{\isasymkappa}}. In case of uncertainty, |
|
28565 | 269 |
these names may be inspected using the \hyperlink{command.print-context}{\mbox{\isa{\isacommand{print{\isacharunderscore}context}}}} command |
25871 | 270 |
or the corresponding ProofGeneral button.% |
271 |
\end{isamarkuptext}% |
|
272 |
\isamarkuptrue% |
|
273 |
% |
|
25247 | 274 |
\isamarkupsubsection{Lifting and parametric types% |
275 |
} |
|
276 |
\isamarkuptrue% |
|
277 |
% |
|
20967 | 278 |
\begin{isamarkuptext}% |
25247 | 279 |
Overloaded definitions giving on class instantiation |
280 |
may include recursion over the syntactic structure of types. |
|
281 |
As a canonical example, we model product semigroups |
|
282 |
using our simple algebra:% |
|
20967 | 283 |
\end{isamarkuptext}% |
284 |
\isamarkuptrue% |
|
28565 | 285 |
% |
286 |
\isadelimquote |
|
287 |
% |
|
288 |
\endisadelimquote |
|
20967 | 289 |
% |
28565 | 290 |
\isatagquote |
291 |
\isacommand{instantiation}\isamarkupfalse% |
|
292 |
\ {\isacharasterisk}\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}semigroup{\isacharcomma}\ semigroup{\isacharparenright}\ semigroup\isanewline |
|
293 |
\isakeyword{begin}\isanewline |
|
294 |
\isanewline |
|
295 |
\isacommand{definition}\isamarkupfalse% |
|
296 |
\isanewline |
|
297 |
\ \ mult{\isacharunderscore}prod{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequoteopen}p\isactrlisub {\isadigit{1}}\ {\isasymotimes}\ p\isactrlisub {\isadigit{2}}\ {\isacharequal}\ {\isacharparenleft}fst\ p\isactrlisub {\isadigit{1}}\ {\isasymotimes}\ fst\ p\isactrlisub {\isadigit{2}}{\isacharcomma}\ snd\ p\isactrlisub {\isadigit{1}}\ {\isasymotimes}\ snd\ p\isactrlisub {\isadigit{2}}{\isacharparenright}{\isachardoublequoteclose}\isanewline |
|
20967 | 298 |
\isanewline |
28565 | 299 |
\isacommand{instance}\isamarkupfalse% |
300 |
\ \isacommand{proof}\isamarkupfalse% |
|
301 |
\isanewline |
|
302 |
\ \ \isacommand{fix}\isamarkupfalse% |
|
25533 | 303 |
\ p\isactrlisub {\isadigit{1}}\ p\isactrlisub {\isadigit{2}}\ p\isactrlisub {\isadigit{3}}\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}{\isasymColon}semigroup\ {\isasymtimes}\ {\isasymbeta}{\isasymColon}semigroup{\isachardoublequoteclose}\isanewline |
28565 | 304 |
\ \ \isacommand{show}\isamarkupfalse% |
25247 | 305 |
\ {\isachardoublequoteopen}p\isactrlisub {\isadigit{1}}\ {\isasymotimes}\ p\isactrlisub {\isadigit{2}}\ {\isasymotimes}\ p\isactrlisub {\isadigit{3}}\ {\isacharequal}\ p\isactrlisub {\isadigit{1}}\ {\isasymotimes}\ {\isacharparenleft}p\isactrlisub {\isadigit{2}}\ {\isasymotimes}\ p\isactrlisub {\isadigit{3}}{\isacharparenright}{\isachardoublequoteclose}\isanewline |
28566 | 306 |
\ \ \ \ \isacommand{unfolding}\isamarkupfalse% |
25247 | 307 |
\ mult{\isacharunderscore}prod{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse% |
308 |
\ {\isacharparenleft}simp\ add{\isacharcolon}\ assoc{\isacharparenright}\isanewline |
|
28565 | 309 |
\isacommand{qed}\isamarkupfalse% |
25533 | 310 |
\ \ \ \ \ \ \isanewline |
311 |
\isanewline |
|
28565 | 312 |
\isacommand{end}\isamarkupfalse% |
313 |
% |
|
314 |
\endisatagquote |
|
315 |
{\isafoldquote}% |
|
316 |
% |
|
317 |
\isadelimquote |
|
318 |
% |
|
319 |
\endisadelimquote |
|
20967 | 320 |
% |
25247 | 321 |
\begin{isamarkuptext}% |
322 |
\noindent Associativity from product semigroups is |
|
323 |
established using |
|
28565 | 324 |
the definition of \isa{{\isacharparenleft}{\isasymotimes}{\isacharparenright}} on products and the hypothetical |
27507 | 325 |
associativity of the type components; these hypotheses |
25247 | 326 |
are facts due to the \isa{semigroup} constraints imposed |
28565 | 327 |
on the type components by the \hyperlink{command.instance}{\mbox{\isa{\isacommand{instance}}}} proposition. |
25247 | 328 |
Indeed, this pattern often occurs with parametric types |
329 |
and type classes.% |
|
330 |
\end{isamarkuptext}% |
|
331 |
\isamarkuptrue% |
|
332 |
% |
|
333 |
\isamarkupsubsection{Subclassing% |
|
20967 | 334 |
} |
335 |
\isamarkuptrue% |
|
336 |
% |
|
337 |
\begin{isamarkuptext}% |
|
22317 | 338 |
We define a subclass \isa{monoidl} (a semigroup with a left-hand neutral) |
20967 | 339 |
by extending \isa{semigroup} |
24991 | 340 |
with one additional parameter \isa{neutral} together |
20967 | 341 |
with its property:% |
342 |
\end{isamarkuptext}% |
|
343 |
\isamarkuptrue% |
|
28565 | 344 |
% |
345 |
\isadelimquote |
|
346 |
% |
|
347 |
\endisadelimquote |
|
348 |
% |
|
349 |
\isatagquote |
|
350 |
\isacommand{class}\isamarkupfalse% |
|
20967 | 351 |
\ monoidl\ {\isacharequal}\ semigroup\ {\isacharplus}\isanewline |
28565 | 352 |
\ \ \isakeyword{fixes}\ neutral\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}{\isachardoublequoteclose}\ {\isacharparenleft}{\isachardoublequoteopen}{\isasymone}{\isachardoublequoteclose}{\isacharparenright}\isanewline |
353 |
\ \ \isakeyword{assumes}\ neutl{\isacharcolon}\ {\isachardoublequoteopen}{\isasymone}\ {\isasymotimes}\ x\ {\isacharequal}\ x{\isachardoublequoteclose}% |
|
354 |
\endisatagquote |
|
355 |
{\isafoldquote}% |
|
356 |
% |
|
357 |
\isadelimquote |
|
358 |
% |
|
359 |
\endisadelimquote |
|
360 |
% |
|
20967 | 361 |
\begin{isamarkuptext}% |
25247 | 362 |
\noindent Again, we prove some instances, by |
24991 | 363 |
providing suitable parameter definitions and proofs for the |
27507 | 364 |
additional specifications. Observe that instantiations |
25533 | 365 |
for types with the same arity may be simultaneous:% |
20967 | 366 |
\end{isamarkuptext}% |
367 |
\isamarkuptrue% |
|
28566 | 368 |
% |
369 |
\isadelimquote |
|
370 |
% |
|
371 |
\endisadelimquote |
|
372 |
% |
|
373 |
\isatagquote |
|
374 |
\isacommand{instantiation}\isamarkupfalse% |
|
25533 | 375 |
\ nat\ \isakeyword{and}\ int\ {\isacharcolon}{\isacharcolon}\ monoidl\isanewline |
28566 | 376 |
\isakeyword{begin}\isanewline |
25533 | 377 |
\isanewline |
28566 | 378 |
\isacommand{definition}\isamarkupfalse% |
25533 | 379 |
\isanewline |
28566 | 380 |
\ \ neutral{\isacharunderscore}nat{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequoteopen}{\isasymone}\ {\isacharequal}\ {\isacharparenleft}{\isadigit{0}}{\isasymColon}nat{\isacharparenright}{\isachardoublequoteclose}\isanewline |
381 |
\isanewline |
|
382 |
\isacommand{definition}\isamarkupfalse% |
|
383 |
\isanewline |
|
384 |
\ \ neutral{\isacharunderscore}int{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequoteopen}{\isasymone}\ {\isacharequal}\ {\isacharparenleft}{\isadigit{0}}{\isasymColon}int{\isacharparenright}{\isachardoublequoteclose}\isanewline |
|
20967 | 385 |
\isanewline |
28566 | 386 |
\isacommand{instance}\isamarkupfalse% |
387 |
\ \isacommand{proof}\isamarkupfalse% |
|
388 |
\isanewline |
|
389 |
\ \ \isacommand{fix}\isamarkupfalse% |
|
20967 | 390 |
\ n\ {\isacharcolon}{\isacharcolon}\ nat\isanewline |
28566 | 391 |
\ \ \isacommand{show}\isamarkupfalse% |
25247 | 392 |
\ {\isachardoublequoteopen}{\isasymone}\ {\isasymotimes}\ n\ {\isacharequal}\ n{\isachardoublequoteclose}\isanewline |
28566 | 393 |
\ \ \ \ \isacommand{unfolding}\isamarkupfalse% |
26991 | 394 |
\ neutral{\isacharunderscore}nat{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse% |
20967 | 395 |
\ simp\isanewline |
28566 | 396 |
\isacommand{next}\isamarkupfalse% |
20967 | 397 |
\isanewline |
28566 | 398 |
\ \ \isacommand{fix}\isamarkupfalse% |
20967 | 399 |
\ k\ {\isacharcolon}{\isacharcolon}\ int\isanewline |
28566 | 400 |
\ \ \isacommand{show}\isamarkupfalse% |
25247 | 401 |
\ {\isachardoublequoteopen}{\isasymone}\ {\isasymotimes}\ k\ {\isacharequal}\ k{\isachardoublequoteclose}\isanewline |
28566 | 402 |
\ \ \ \ \isacommand{unfolding}\isamarkupfalse% |
20967 | 403 |
\ neutral{\isacharunderscore}int{\isacharunderscore}def\ mult{\isacharunderscore}int{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse% |
404 |
\ simp\isanewline |
|
28566 | 405 |
\isacommand{qed}\isamarkupfalse% |
20967 | 406 |
\isanewline |
25533 | 407 |
\isanewline |
28566 | 408 |
\isacommand{end}\isamarkupfalse% |
25533 | 409 |
\isanewline |
410 |
\isanewline |
|
28566 | 411 |
\isacommand{instantiation}\isamarkupfalse% |
25247 | 412 |
\ {\isacharasterisk}\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}monoidl{\isacharcomma}\ monoidl{\isacharparenright}\ monoidl\isanewline |
28566 | 413 |
\isakeyword{begin}\isanewline |
25533 | 414 |
\isanewline |
28566 | 415 |
\isacommand{definition}\isamarkupfalse% |
25533 | 416 |
\isanewline |
28566 | 417 |
\ \ neutral{\isacharunderscore}prod{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequoteopen}{\isasymone}\ {\isacharequal}\ {\isacharparenleft}{\isasymone}{\isacharcomma}\ {\isasymone}{\isacharparenright}{\isachardoublequoteclose}\isanewline |
25533 | 418 |
\isanewline |
28566 | 419 |
\isacommand{instance}\isamarkupfalse% |
420 |
\ \isacommand{proof}\isamarkupfalse% |
|
20967 | 421 |
\isanewline |
28566 | 422 |
\ \ \isacommand{fix}\isamarkupfalse% |
25533 | 423 |
\ p\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}{\isasymColon}monoidl\ {\isasymtimes}\ {\isasymbeta}{\isasymColon}monoidl{\isachardoublequoteclose}\isanewline |
28566 | 424 |
\ \ \isacommand{show}\isamarkupfalse% |
25247 | 425 |
\ {\isachardoublequoteopen}{\isasymone}\ {\isasymotimes}\ p\ {\isacharequal}\ p{\isachardoublequoteclose}\isanewline |
28566 | 426 |
\ \ \ \ \isacommand{unfolding}\isamarkupfalse% |
25247 | 427 |
\ neutral{\isacharunderscore}prod{\isacharunderscore}def\ mult{\isacharunderscore}prod{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse% |
428 |
\ {\isacharparenleft}simp\ add{\isacharcolon}\ neutl{\isacharparenright}\isanewline |
|
28566 | 429 |
\isacommand{qed}\isamarkupfalse% |
25533 | 430 |
\isanewline |
431 |
\isanewline |
|
28566 | 432 |
\isacommand{end}\isamarkupfalse% |
433 |
% |
|
434 |
\endisatagquote |
|
435 |
{\isafoldquote}% |
|
436 |
% |
|
437 |
\isadelimquote |
|
438 |
% |
|
439 |
\endisadelimquote |
|
20967 | 440 |
% |
441 |
\begin{isamarkuptext}% |
|
22317 | 442 |
\noindent Fully-fledged monoids are modelled by another subclass |
24991 | 443 |
which does not add new parameters but tightens the specification:% |
20967 | 444 |
\end{isamarkuptext}% |
445 |
\isamarkuptrue% |
|
28566 | 446 |
% |
447 |
\isadelimquote |
|
448 |
% |
|
449 |
\endisadelimquote |
|
20967 | 450 |
% |
28566 | 451 |
\isatagquote |
452 |
\isacommand{class}\isamarkupfalse% |
|
453 |
\ monoid\ {\isacharequal}\ monoidl\ {\isacharplus}\isanewline |
|
454 |
\ \ \isakeyword{assumes}\ neutr{\isacharcolon}\ {\isachardoublequoteopen}x\ {\isasymotimes}\ {\isasymone}\ {\isacharequal}\ x{\isachardoublequoteclose}\isanewline |
|
455 |
\isanewline |
|
456 |
\isacommand{instantiation}\isamarkupfalse% |
|
457 |
\ nat\ \isakeyword{and}\ int\ {\isacharcolon}{\isacharcolon}\ monoid\ \isanewline |
|
458 |
\isakeyword{begin}\isanewline |
|
20967 | 459 |
\isanewline |
28566 | 460 |
\isacommand{instance}\isamarkupfalse% |
461 |
\ \isacommand{proof}\isamarkupfalse% |
|
462 |
\isanewline |
|
463 |
\ \ \isacommand{fix}\isamarkupfalse% |
|
20967 | 464 |
\ n\ {\isacharcolon}{\isacharcolon}\ nat\isanewline |
28566 | 465 |
\ \ \isacommand{show}\isamarkupfalse% |
25247 | 466 |
\ {\isachardoublequoteopen}n\ {\isasymotimes}\ {\isasymone}\ {\isacharequal}\ n{\isachardoublequoteclose}\isanewline |
28566 | 467 |
\ \ \ \ \isacommand{unfolding}\isamarkupfalse% |
25871 | 468 |
\ neutral{\isacharunderscore}nat{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse% |
469 |
\ {\isacharparenleft}induct\ n{\isacharparenright}\ simp{\isacharunderscore}all\isanewline |
|
28566 | 470 |
\isacommand{next}\isamarkupfalse% |
20967 | 471 |
\isanewline |
28566 | 472 |
\ \ \isacommand{fix}\isamarkupfalse% |
20967 | 473 |
\ k\ {\isacharcolon}{\isacharcolon}\ int\isanewline |
28566 | 474 |
\ \ \isacommand{show}\isamarkupfalse% |
25247 | 475 |
\ {\isachardoublequoteopen}k\ {\isasymotimes}\ {\isasymone}\ {\isacharequal}\ k{\isachardoublequoteclose}\isanewline |
28566 | 476 |
\ \ \ \ \isacommand{unfolding}\isamarkupfalse% |
20967 | 477 |
\ neutral{\isacharunderscore}int{\isacharunderscore}def\ mult{\isacharunderscore}int{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse% |
478 |
\ simp\isanewline |
|
28566 | 479 |
\isacommand{qed}\isamarkupfalse% |
20967 | 480 |
\isanewline |
25533 | 481 |
\isanewline |
28566 | 482 |
\isacommand{end}\isamarkupfalse% |
25533 | 483 |
\isanewline |
484 |
\isanewline |
|
28566 | 485 |
\isacommand{instantiation}\isamarkupfalse% |
25533 | 486 |
\ {\isacharasterisk}\ {\isacharcolon}{\isacharcolon}\ {\isacharparenleft}monoid{\isacharcomma}\ monoid{\isacharparenright}\ monoid\isanewline |
28566 | 487 |
\isakeyword{begin}\isanewline |
25533 | 488 |
\isanewline |
28566 | 489 |
\isacommand{instance}\isamarkupfalse% |
490 |
\ \isacommand{proof}\isamarkupfalse% |
|
25247 | 491 |
\ \isanewline |
28566 | 492 |
\ \ \isacommand{fix}\isamarkupfalse% |
25533 | 493 |
\ p\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}{\isasymColon}monoid\ {\isasymtimes}\ {\isasymbeta}{\isasymColon}monoid{\isachardoublequoteclose}\isanewline |
28566 | 494 |
\ \ \isacommand{show}\isamarkupfalse% |
25247 | 495 |
\ {\isachardoublequoteopen}p\ {\isasymotimes}\ {\isasymone}\ {\isacharequal}\ p{\isachardoublequoteclose}\isanewline |
28566 | 496 |
\ \ \ \ \isacommand{unfolding}\isamarkupfalse% |
25247 | 497 |
\ neutral{\isacharunderscore}prod{\isacharunderscore}def\ mult{\isacharunderscore}prod{\isacharunderscore}def\ \isacommand{by}\isamarkupfalse% |
498 |
\ {\isacharparenleft}simp\ add{\isacharcolon}\ neutr{\isacharparenright}\isanewline |
|
28566 | 499 |
\isacommand{qed}\isamarkupfalse% |
25533 | 500 |
\isanewline |
501 |
\isanewline |
|
28566 | 502 |
\isacommand{end}\isamarkupfalse% |
503 |
% |
|
504 |
\endisatagquote |
|
505 |
{\isafoldquote}% |
|
506 |
% |
|
507 |
\isadelimquote |
|
508 |
% |
|
509 |
\endisadelimquote |
|
22317 | 510 |
% |
511 |
\begin{isamarkuptext}% |
|
512 |
\noindent To finish our small algebra example, we add a \isa{group} class |
|
513 |
with a corresponding instance:% |
|
514 |
\end{isamarkuptext}% |
|
515 |
\isamarkuptrue% |
|
28566 | 516 |
% |
517 |
\isadelimquote |
|
518 |
% |
|
519 |
\endisadelimquote |
|
520 |
% |
|
521 |
\isatagquote |
|
522 |
\isacommand{class}\isamarkupfalse% |
|
20967 | 523 |
\ group\ {\isacharequal}\ monoidl\ {\isacharplus}\isanewline |
28566 | 524 |
\ \ \isakeyword{fixes}\ inverse\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}\ \ \ \ {\isacharparenleft}{\isachardoublequoteopen}{\isacharparenleft}{\isacharunderscore}{\isasymdiv}{\isacharparenright}{\isachardoublequoteclose}\ {\isacharbrackleft}{\isadigit{1}}{\isadigit{0}}{\isadigit{0}}{\isadigit{0}}{\isacharbrackright}\ {\isadigit{9}}{\isadigit{9}}{\isadigit{9}}{\isacharparenright}\isanewline |
525 |
\ \ \isakeyword{assumes}\ invl{\isacharcolon}\ {\isachardoublequoteopen}x{\isasymdiv}\ {\isasymotimes}\ x\ {\isacharequal}\ {\isasymone}{\isachardoublequoteclose}\isanewline |
|
25533 | 526 |
\isanewline |
28566 | 527 |
\isacommand{instantiation}\isamarkupfalse% |
528 |
\ int\ {\isacharcolon}{\isacharcolon}\ group\isanewline |
|
529 |
\isakeyword{begin}\isanewline |
|
530 |
\isanewline |
|
531 |
\isacommand{definition}\isamarkupfalse% |
|
20967 | 532 |
\isanewline |
28566 | 533 |
\ \ inverse{\isacharunderscore}int{\isacharunderscore}def{\isacharcolon}\ {\isachardoublequoteopen}i{\isasymdiv}\ {\isacharequal}\ {\isacharminus}\ {\isacharparenleft}i{\isasymColon}int{\isacharparenright}{\isachardoublequoteclose}\isanewline |
534 |
\isanewline |
|
535 |
\isacommand{instance}\isamarkupfalse% |
|
536 |
\ \isacommand{proof}\isamarkupfalse% |
|
537 |
\isanewline |
|
538 |
\ \ \isacommand{fix}\isamarkupfalse% |
|
20967 | 539 |
\ i\ {\isacharcolon}{\isacharcolon}\ int\isanewline |
28566 | 540 |
\ \ \isacommand{have}\isamarkupfalse% |
20967 | 541 |
\ {\isachardoublequoteopen}{\isacharminus}i\ {\isacharplus}\ i\ {\isacharequal}\ {\isadigit{0}}{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse% |
542 |
\ simp\isanewline |
|
28566 | 543 |
\ \ \isacommand{then}\isamarkupfalse% |
20967 | 544 |
\ \isacommand{show}\isamarkupfalse% |
22550 | 545 |
\ {\isachardoublequoteopen}i{\isasymdiv}\ {\isasymotimes}\ i\ {\isacharequal}\ {\isasymone}{\isachardoublequoteclose}\isanewline |
28566 | 546 |
\ \ \ \ \isacommand{unfolding}\isamarkupfalse% |
25247 | 547 |
\ mult{\isacharunderscore}int{\isacharunderscore}def\ neutral{\isacharunderscore}int{\isacharunderscore}def\ inverse{\isacharunderscore}int{\isacharunderscore}def\ \isacommand{{\isachardot}}\isamarkupfalse% |
20967 | 548 |
\isanewline |
28566 | 549 |
\isacommand{qed}\isamarkupfalse% |
25533 | 550 |
\isanewline |
551 |
\isanewline |
|
28566 | 552 |
\isacommand{end}\isamarkupfalse% |
553 |
% |
|
554 |
\endisatagquote |
|
555 |
{\isafoldquote}% |
|
556 |
% |
|
557 |
\isadelimquote |
|
558 |
% |
|
559 |
\endisadelimquote |
|
20967 | 560 |
% |
22317 | 561 |
\isamarkupsection{Type classes as locales% |
562 |
} |
|
563 |
\isamarkuptrue% |
|
564 |
% |
|
565 |
\isamarkupsubsection{A look behind the scene% |
|
566 |
} |
|
567 |
\isamarkuptrue% |
|
568 |
% |
|
569 |
\begin{isamarkuptext}% |
|
22479 | 570 |
The example above gives an impression how Isar type classes work |
571 |
in practice. As stated in the introduction, classes also provide |
|
572 |
a link to Isar's locale system. Indeed, the logical core of a class |
|
573 |
is nothing else than a locale:% |
|
574 |
\end{isamarkuptext}% |
|
575 |
\isamarkuptrue% |
|
28566 | 576 |
% |
577 |
\isadelimquote |
|
578 |
% |
|
579 |
\endisadelimquote |
|
580 |
% |
|
581 |
\isatagquote |
|
22479 | 582 |
\isacommand{class}\isamarkupfalse% |
29705 | 583 |
\ idem\ {\isacharequal}\isanewline |
22479 | 584 |
\ \ \isakeyword{fixes}\ f\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}\isanewline |
585 |
\ \ \isakeyword{assumes}\ idem{\isacharcolon}\ {\isachardoublequoteopen}f\ {\isacharparenleft}f\ x{\isacharparenright}\ {\isacharequal}\ f\ x{\isachardoublequoteclose}% |
|
28566 | 586 |
\endisatagquote |
587 |
{\isafoldquote}% |
|
588 |
% |
|
589 |
\isadelimquote |
|
590 |
% |
|
591 |
\endisadelimquote |
|
592 |
% |
|
22479 | 593 |
\begin{isamarkuptext}% |
594 |
\noindent essentially introduces the locale% |
|
595 |
\end{isamarkuptext}% |
|
596 |
\isamarkuptrue% |
|
30227 | 597 |
\ % |
28565 | 598 |
\isadeliminvisible |
30227 | 599 |
% |
28565 | 600 |
\endisadeliminvisible |
22479 | 601 |
% |
28565 | 602 |
\isataginvisible |
30227 | 603 |
% |
28565 | 604 |
\endisataginvisible |
605 |
{\isafoldinvisible}% |
|
22479 | 606 |
% |
28565 | 607 |
\isadeliminvisible |
22479 | 608 |
% |
28565 | 609 |
\endisadeliminvisible |
28566 | 610 |
% |
611 |
\isadelimquote |
|
612 |
% |
|
613 |
\endisadelimquote |
|
614 |
% |
|
615 |
\isatagquote |
|
22479 | 616 |
\isacommand{locale}\isamarkupfalse% |
617 |
\ idem\ {\isacharequal}\isanewline |
|
618 |
\ \ \isakeyword{fixes}\ f\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}\isanewline |
|
619 |
\ \ \isakeyword{assumes}\ idem{\isacharcolon}\ {\isachardoublequoteopen}f\ {\isacharparenleft}f\ x{\isacharparenright}\ {\isacharequal}\ f\ x{\isachardoublequoteclose}% |
|
28566 | 620 |
\endisatagquote |
621 |
{\isafoldquote}% |
|
622 |
% |
|
623 |
\isadelimquote |
|
624 |
% |
|
625 |
\endisadelimquote |
|
626 |
% |
|
22479 | 627 |
\begin{isamarkuptext}% |
22550 | 628 |
\noindent together with corresponding constant(s):% |
22479 | 629 |
\end{isamarkuptext}% |
630 |
\isamarkuptrue% |
|
28566 | 631 |
% |
632 |
\isadelimquote |
|
633 |
% |
|
634 |
\endisadelimquote |
|
635 |
% |
|
636 |
\isatagquote |
|
22479 | 637 |
\isacommand{consts}\isamarkupfalse% |
22550 | 638 |
\ f\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}% |
28566 | 639 |
\endisatagquote |
640 |
{\isafoldquote}% |
|
641 |
% |
|
642 |
\isadelimquote |
|
643 |
% |
|
644 |
\endisadelimquote |
|
645 |
% |
|
22550 | 646 |
\begin{isamarkuptext}% |
647 |
\noindent The connection to the type system is done by means |
|
648 |
of a primitive axclass% |
|
649 |
\end{isamarkuptext}% |
|
650 |
\isamarkuptrue% |
|
30227 | 651 |
\ % |
29513 | 652 |
\isadeliminvisible |
30227 | 653 |
% |
29513 | 654 |
\endisadeliminvisible |
655 |
% |
|
656 |
\isataginvisible |
|
30227 | 657 |
% |
29513 | 658 |
\endisataginvisible |
659 |
{\isafoldinvisible}% |
|
660 |
% |
|
661 |
\isadeliminvisible |
|
662 |
% |
|
663 |
\endisadeliminvisible |
|
664 |
% |
|
28566 | 665 |
\isadelimquote |
666 |
% |
|
667 |
\endisadelimquote |
|
668 |
% |
|
669 |
\isatagquote |
|
22479 | 670 |
\isacommand{axclass}\isamarkupfalse% |
671 |
\ idem\ {\isacharless}\ type\isanewline |
|
30227 | 672 |
\ \ idem{\isacharcolon}\ {\isachardoublequoteopen}f\ {\isacharparenleft}f\ x{\isacharparenright}\ {\isacharequal}\ f\ x{\isachardoublequoteclose}\ % |
28566 | 673 |
\endisatagquote |
674 |
{\isafoldquote}% |
|
675 |
% |
|
676 |
\isadelimquote |
|
677 |
% |
|
678 |
\endisadelimquote |
|
679 |
% |
|
29513 | 680 |
\isadeliminvisible |
30227 | 681 |
% |
29513 | 682 |
\endisadeliminvisible |
683 |
% |
|
684 |
\isataginvisible |
|
30227 | 685 |
% |
29513 | 686 |
\endisataginvisible |
687 |
{\isafoldinvisible}% |
|
688 |
% |
|
689 |
\isadeliminvisible |
|
690 |
% |
|
691 |
\endisadeliminvisible |
|
692 |
% |
|
22479 | 693 |
\begin{isamarkuptext}% |
22649 | 694 |
\noindent together with a corresponding interpretation:% |
22479 | 695 |
\end{isamarkuptext}% |
696 |
\isamarkuptrue% |
|
28566 | 697 |
% |
698 |
\isadelimquote |
|
699 |
% |
|
700 |
\endisadelimquote |
|
701 |
% |
|
702 |
\isatagquote |
|
22479 | 703 |
\isacommand{interpretation}\isamarkupfalse% |
29513 | 704 |
\ idem{\isacharunderscore}class{\isacharcolon}\isanewline |
29297 | 705 |
\ \ idem\ {\isachardoublequoteopen}f\ {\isasymColon}\ {\isacharparenleft}{\isasymalpha}{\isasymColon}idem{\isacharparenright}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}\isanewline |
28947
ac1a14b5a085
unfold_locales is default method - no need for explicit references
haftmann
parents:
28727
diff
changeset
|
706 |
\isacommand{proof}\isamarkupfalse% |
ac1a14b5a085
unfold_locales is default method - no need for explicit references
haftmann
parents:
28727
diff
changeset
|
707 |
\ \isacommand{qed}\isamarkupfalse% |
ac1a14b5a085
unfold_locales is default method - no need for explicit references
haftmann
parents:
28727
diff
changeset
|
708 |
\ {\isacharparenleft}rule\ idem{\isacharparenright}% |
28566 | 709 |
\endisatagquote |
710 |
{\isafoldquote}% |
|
711 |
% |
|
712 |
\isadelimquote |
|
713 |
% |
|
714 |
\endisadelimquote |
|
22479 | 715 |
% |
28566 | 716 |
\begin{isamarkuptext}% |
717 |
\noindent This gives you at hand the full power of the Isabelle module system; |
|
718 |
conclusions in locale \isa{idem} are implicitly propagated |
|
719 |
to class \isa{idem}.% |
|
720 |
\end{isamarkuptext}% |
|
721 |
\isamarkuptrue% |
|
30227 | 722 |
\ % |
28565 | 723 |
\isadeliminvisible |
30227 | 724 |
% |
28565 | 725 |
\endisadeliminvisible |
22479 | 726 |
% |
28565 | 727 |
\isataginvisible |
30227 | 728 |
% |
28565 | 729 |
\endisataginvisible |
730 |
{\isafoldinvisible}% |
|
22479 | 731 |
% |
28565 | 732 |
\isadeliminvisible |
22479 | 733 |
% |
28565 | 734 |
\endisadeliminvisible |
22479 | 735 |
% |
20967 | 736 |
\isamarkupsubsection{Abstract reasoning% |
737 |
} |
|
738 |
\isamarkuptrue% |
|
739 |
% |
|
740 |
\begin{isamarkuptext}% |
|
22479 | 741 |
Isabelle locales enable reasoning at a general level, while results |
20967 | 742 |
are implicitly transferred to all instances. For example, we can |
743 |
now establish the \isa{left{\isacharunderscore}cancel} lemma for groups, which |
|
25247 | 744 |
states that the function \isa{{\isacharparenleft}x\ {\isasymotimes}{\isacharparenright}} is injective:% |
20967 | 745 |
\end{isamarkuptext}% |
746 |
\isamarkuptrue% |
|
28566 | 747 |
% |
748 |
\isadelimquote |
|
20967 | 749 |
% |
28566 | 750 |
\endisadelimquote |
20967 | 751 |
% |
28566 | 752 |
\isatagquote |
753 |
\isacommand{lemma}\isamarkupfalse% |
|
754 |
\ {\isacharparenleft}\isakeyword{in}\ group{\isacharparenright}\ left{\isacharunderscore}cancel{\isacharcolon}\ {\isachardoublequoteopen}x\ {\isasymotimes}\ y\ {\isacharequal}\ x\ {\isasymotimes}\ z\ {\isasymlongleftrightarrow}\ y\ {\isacharequal}\ z{\isachardoublequoteclose}\isanewline |
|
20967 | 755 |
\isacommand{proof}\isamarkupfalse% |
756 |
\isanewline |
|
28566 | 757 |
\ \ \isacommand{assume}\isamarkupfalse% |
25200 | 758 |
\ {\isachardoublequoteopen}x\ {\isasymotimes}\ y\ {\isacharequal}\ x\ {\isasymotimes}\ z{\isachardoublequoteclose}\isanewline |
28566 | 759 |
\ \ \isacommand{then}\isamarkupfalse% |
20967 | 760 |
\ \isacommand{have}\isamarkupfalse% |
25200 | 761 |
\ {\isachardoublequoteopen}x{\isasymdiv}\ {\isasymotimes}\ {\isacharparenleft}x\ {\isasymotimes}\ y{\isacharparenright}\ {\isacharequal}\ x{\isasymdiv}\ {\isasymotimes}\ {\isacharparenleft}x\ {\isasymotimes}\ z{\isacharparenright}{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse% |
20967 | 762 |
\ simp\isanewline |
28566 | 763 |
\ \ \isacommand{then}\isamarkupfalse% |
20967 | 764 |
\ \isacommand{have}\isamarkupfalse% |
25200 | 765 |
\ {\isachardoublequoteopen}{\isacharparenleft}x{\isasymdiv}\ {\isasymotimes}\ x{\isacharparenright}\ {\isasymotimes}\ y\ {\isacharequal}\ {\isacharparenleft}x{\isasymdiv}\ {\isasymotimes}\ x{\isacharparenright}\ {\isasymotimes}\ z{\isachardoublequoteclose}\ \isacommand{using}\isamarkupfalse% |
20967 | 766 |
\ assoc\ \isacommand{by}\isamarkupfalse% |
767 |
\ simp\isanewline |
|
28566 | 768 |
\ \ \isacommand{then}\isamarkupfalse% |
20967 | 769 |
\ \isacommand{show}\isamarkupfalse% |
770 |
\ {\isachardoublequoteopen}y\ {\isacharequal}\ z{\isachardoublequoteclose}\ \isacommand{using}\isamarkupfalse% |
|
771 |
\ neutl\ \isakeyword{and}\ invl\ \isacommand{by}\isamarkupfalse% |
|
772 |
\ simp\isanewline |
|
28566 | 773 |
\isacommand{next}\isamarkupfalse% |
20967 | 774 |
\isanewline |
28566 | 775 |
\ \ \isacommand{assume}\isamarkupfalse% |
20967 | 776 |
\ {\isachardoublequoteopen}y\ {\isacharequal}\ z{\isachardoublequoteclose}\isanewline |
28566 | 777 |
\ \ \isacommand{then}\isamarkupfalse% |
20967 | 778 |
\ \isacommand{show}\isamarkupfalse% |
25200 | 779 |
\ {\isachardoublequoteopen}x\ {\isasymotimes}\ y\ {\isacharequal}\ x\ {\isasymotimes}\ z{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse% |
20967 | 780 |
\ simp\isanewline |
28566 | 781 |
\isacommand{qed}\isamarkupfalse% |
20967 | 782 |
% |
28566 | 783 |
\endisatagquote |
784 |
{\isafoldquote}% |
|
20967 | 785 |
% |
28566 | 786 |
\isadelimquote |
20967 | 787 |
% |
28566 | 788 |
\endisadelimquote |
20967 | 789 |
% |
790 |
\begin{isamarkuptext}% |
|
28565 | 791 |
\noindent Here the \qt{\hyperlink{keyword.in}{\mbox{\isa{\isakeyword{in}}}} \isa{group}} target specification |
20967 | 792 |
indicates that the result is recorded within that context for later |
28565 | 793 |
use. This local theorem is also lifted to the global one \hyperlink{fact.group.left-cancel:}{\mbox{\isa{group{\isachardot}left{\isacharunderscore}cancel{\isacharcolon}}}} \isa{{\isachardoublequote}{\isasymAnd}x\ y\ z\ {\isasymColon}\ {\isasymalpha}{\isasymColon}group{\isachardot}\ x\ {\isasymotimes}\ y\ {\isacharequal}\ x\ {\isasymotimes}\ z\ {\isasymlongleftrightarrow}\ y\ {\isacharequal}\ z{\isachardoublequote}}. Since type \isa{int} has been made an instance of |
22479 | 794 |
\isa{group} before, we may refer to that fact as well: \isa{{\isachardoublequote}{\isasymAnd}x\ y\ z\ {\isasymColon}\ int{\isachardot}\ x\ {\isasymotimes}\ y\ {\isacharequal}\ x\ {\isasymotimes}\ z\ {\isasymlongleftrightarrow}\ y\ {\isacharequal}\ z{\isachardoublequote}}.% |
20967 | 795 |
\end{isamarkuptext}% |
796 |
\isamarkuptrue% |
|
797 |
% |
|
23956 | 798 |
\isamarkupsubsection{Derived definitions% |
799 |
} |
|
800 |
\isamarkuptrue% |
|
801 |
% |
|
802 |
\begin{isamarkuptext}% |
|
803 |
Isabelle locales support a concept of local definitions |
|
804 |
in locales:% |
|
805 |
\end{isamarkuptext}% |
|
806 |
\isamarkuptrue% |
|
28566 | 807 |
% |
808 |
\isadelimquote |
|
809 |
% |
|
810 |
\endisadelimquote |
|
811 |
% |
|
812 |
\isatagquote |
|
813 |
\isacommand{primrec}\isamarkupfalse% |
|
28540 | 814 |
\ {\isacharparenleft}\isakeyword{in}\ monoid{\isacharparenright}\ pow{\isacharunderscore}nat\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}\ \isakeyword{where}\isanewline |
28566 | 815 |
\ \ {\isachardoublequoteopen}pow{\isacharunderscore}nat\ {\isadigit{0}}\ x\ {\isacharequal}\ {\isasymone}{\isachardoublequoteclose}\isanewline |
816 |
\ \ {\isacharbar}\ {\isachardoublequoteopen}pow{\isacharunderscore}nat\ {\isacharparenleft}Suc\ n{\isacharparenright}\ x\ {\isacharequal}\ x\ {\isasymotimes}\ pow{\isacharunderscore}nat\ n\ x{\isachardoublequoteclose}% |
|
817 |
\endisatagquote |
|
818 |
{\isafoldquote}% |
|
819 |
% |
|
820 |
\isadelimquote |
|
821 |
% |
|
822 |
\endisadelimquote |
|
823 |
% |
|
23956 | 824 |
\begin{isamarkuptext}% |
825 |
\noindent If the locale \isa{group} is also a class, this local |
|
826 |
definition is propagated onto a global definition of |
|
827 |
\isa{{\isachardoublequote}pow{\isacharunderscore}nat\ {\isasymColon}\ nat\ {\isasymRightarrow}\ {\isasymalpha}{\isasymColon}monoid\ {\isasymRightarrow}\ {\isasymalpha}{\isasymColon}monoid{\isachardoublequote}} |
|
828 |
with corresponding theorems |
|
829 |
||
830 |
\isa{pow{\isacharunderscore}nat\ {\isadigit{0}}\ x\ {\isacharequal}\ {\isasymone}\isasep\isanewline% |
|
831 |
pow{\isacharunderscore}nat\ {\isacharparenleft}Suc\ n{\isacharparenright}\ x\ {\isacharequal}\ x\ {\isasymotimes}\ pow{\isacharunderscore}nat\ n\ x}. |
|
832 |
||
833 |
\noindent As you can see from this example, for local |
|
834 |
definitions you may use any specification tool |
|
835 |
which works together with locales (e.g. \cite{krauss2006}).% |
|
836 |
\end{isamarkuptext}% |
|
837 |
\isamarkuptrue% |
|
838 |
% |
|
25247 | 839 |
\isamarkupsubsection{A functor analogy% |
840 |
} |
|
841 |
\isamarkuptrue% |
|
842 |
% |
|
843 |
\begin{isamarkuptext}% |
|
844 |
We introduced Isar classes by analogy to type classes |
|
845 |
functional programming; if we reconsider this in the |
|
846 |
context of what has been said about type classes and locales, |
|
847 |
we can drive this analogy further by stating that type |
|
848 |
classes essentially correspond to functors which have |
|
849 |
a canonical interpretation as type classes. |
|
850 |
Anyway, there is also the possibility of other interpretations. |
|
851 |
For example, also \isa{list}s form a monoid with |
|
28565 | 852 |
\isa{append} and \isa{{\isacharbrackleft}{\isacharbrackright}} as operations, but it |
25247 | 853 |
seems inappropriate to apply to lists |
27507 | 854 |
the same operations as for genuinely algebraic types. |
25247 | 855 |
In such a case, we simply can do a particular interpretation |
856 |
of monoids for lists:% |
|
857 |
\end{isamarkuptext}% |
|
858 |
\isamarkuptrue% |
|
859 |
% |
|
28566 | 860 |
\isadelimquote |
861 |
% |
|
862 |
\endisadelimquote |
|
25247 | 863 |
% |
28566 | 864 |
\isatagquote |
29513 | 865 |
\isacommand{interpretation}\isamarkupfalse% |
866 |
\ list{\isacharunderscore}monoid{\isacharbang}{\isacharcolon}\ monoid\ append\ {\isachardoublequoteopen}{\isacharbrackleft}{\isacharbrackright}{\isachardoublequoteclose}\isanewline |
|
28947
ac1a14b5a085
unfold_locales is default method - no need for explicit references
haftmann
parents:
28727
diff
changeset
|
867 |
\ \ \isacommand{proof}\isamarkupfalse% |
ac1a14b5a085
unfold_locales is default method - no need for explicit references
haftmann
parents:
28727
diff
changeset
|
868 |
\ \isacommand{qed}\isamarkupfalse% |
ac1a14b5a085
unfold_locales is default method - no need for explicit references
haftmann
parents:
28727
diff
changeset
|
869 |
\ auto% |
28566 | 870 |
\endisatagquote |
871 |
{\isafoldquote}% |
|
25247 | 872 |
% |
28566 | 873 |
\isadelimquote |
25247 | 874 |
% |
28566 | 875 |
\endisadelimquote |
25247 | 876 |
% |
877 |
\begin{isamarkuptext}% |
|
878 |
\noindent This enables us to apply facts on monoids |
|
879 |
to lists, e.g. \isa{{\isacharbrackleft}{\isacharbrackright}\ {\isacharat}\ x\ {\isacharequal}\ x}. |
|
880 |
||
881 |
When using this interpretation pattern, it may also |
|
882 |
be appropriate to map derived definitions accordingly:% |
|
883 |
\end{isamarkuptext}% |
|
884 |
\isamarkuptrue% |
|
28566 | 885 |
% |
886 |
\isadelimquote |
|
887 |
% |
|
888 |
\endisadelimquote |
|
889 |
% |
|
890 |
\isatagquote |
|
891 |
\isacommand{primrec}\isamarkupfalse% |
|
28540 | 892 |
\ replicate\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymRightarrow}\ {\isasymalpha}\ list\ {\isasymRightarrow}\ {\isasymalpha}\ list{\isachardoublequoteclose}\ \isakeyword{where}\isanewline |
28566 | 893 |
\ \ {\isachardoublequoteopen}replicate\ {\isadigit{0}}\ {\isacharunderscore}\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}{\isachardoublequoteclose}\isanewline |
894 |
\ \ {\isacharbar}\ {\isachardoublequoteopen}replicate\ {\isacharparenleft}Suc\ n{\isacharparenright}\ xs\ {\isacharequal}\ xs\ {\isacharat}\ replicate\ n\ xs{\isachardoublequoteclose}\isanewline |
|
25247 | 895 |
\isanewline |
29513 | 896 |
\isacommand{interpretation}\isamarkupfalse% |
897 |
\ list{\isacharunderscore}monoid{\isacharbang}{\isacharcolon}\ monoid\ append\ {\isachardoublequoteopen}{\isacharbrackleft}{\isacharbrackright}{\isachardoublequoteclose}\ \isakeyword{where}\isanewline |
|
28566 | 898 |
\ \ {\isachardoublequoteopen}monoid{\isachardot}pow{\isacharunderscore}nat\ append\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharequal}\ replicate{\isachardoublequoteclose}\isanewline |
25247 | 899 |
\isacommand{proof}\isamarkupfalse% |
28540 | 900 |
\ {\isacharminus}\isanewline |
29513 | 901 |
\ \ \isacommand{interpret}\isamarkupfalse% |
902 |
\ monoid\ append\ {\isachardoublequoteopen}{\isacharbrackleft}{\isacharbrackright}{\isachardoublequoteclose}\ \isacommand{{\isachardot}{\isachardot}}\isamarkupfalse% |
|
25247 | 903 |
\isanewline |
28566 | 904 |
\ \ \isacommand{show}\isamarkupfalse% |
28565 | 905 |
\ {\isachardoublequoteopen}monoid{\isachardot}pow{\isacharunderscore}nat\ append\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharequal}\ replicate{\isachardoublequoteclose}\isanewline |
28566 | 906 |
\ \ \isacommand{proof}\isamarkupfalse% |
28540 | 907 |
\isanewline |
28566 | 908 |
\ \ \ \ \isacommand{fix}\isamarkupfalse% |
28540 | 909 |
\ n\isanewline |
28566 | 910 |
\ \ \ \ \isacommand{show}\isamarkupfalse% |
28565 | 911 |
\ {\isachardoublequoteopen}monoid{\isachardot}pow{\isacharunderscore}nat\ append\ {\isacharbrackleft}{\isacharbrackright}\ n\ {\isacharequal}\ replicate\ n{\isachardoublequoteclose}\isanewline |
28566 | 912 |
\ \ \ \ \ \ \isacommand{by}\isamarkupfalse% |
25247 | 913 |
\ {\isacharparenleft}induct\ n{\isacharparenright}\ auto\isanewline |
28566 | 914 |
\ \ \isacommand{qed}\isamarkupfalse% |
28540 | 915 |
\isanewline |
28566 | 916 |
\isacommand{qed}\isamarkupfalse% |
28540 | 917 |
\ intro{\isacharunderscore}locales% |
28566 | 918 |
\endisatagquote |
919 |
{\isafoldquote}% |
|
25247 | 920 |
% |
28566 | 921 |
\isadelimquote |
25247 | 922 |
% |
28566 | 923 |
\endisadelimquote |
25247 | 924 |
% |
24991 | 925 |
\isamarkupsubsection{Additional subclass relations% |
926 |
} |
|
927 |
\isamarkuptrue% |
|
928 |
% |
|
929 |
\begin{isamarkuptext}% |
|
930 |
Any \isa{group} is also a \isa{monoid}; this |
|
25247 | 931 |
can be made explicit by claiming an additional |
932 |
subclass relation, |
|
24991 | 933 |
together with a proof of the logical difference:% |
934 |
\end{isamarkuptext}% |
|
935 |
\isamarkuptrue% |
|
28566 | 936 |
% |
937 |
\isadelimquote |
|
24991 | 938 |
% |
28566 | 939 |
\endisadelimquote |
24991 | 940 |
% |
28566 | 941 |
\isatagquote |
942 |
\isacommand{subclass}\isamarkupfalse% |
|
943 |
\ {\isacharparenleft}\isakeyword{in}\ group{\isacharparenright}\ monoid\isanewline |
|
24991 | 944 |
\isacommand{proof}\isamarkupfalse% |
28947
ac1a14b5a085
unfold_locales is default method - no need for explicit references
haftmann
parents:
28727
diff
changeset
|
945 |
\isanewline |
28566 | 946 |
\ \ \isacommand{fix}\isamarkupfalse% |
24991 | 947 |
\ x\isanewline |
28566 | 948 |
\ \ \isacommand{from}\isamarkupfalse% |
24991 | 949 |
\ invl\ \isacommand{have}\isamarkupfalse% |
25200 | 950 |
\ {\isachardoublequoteopen}x{\isasymdiv}\ {\isasymotimes}\ x\ {\isacharequal}\ {\isasymone}{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse% |
24991 | 951 |
\ simp\isanewline |
28566 | 952 |
\ \ \isacommand{with}\isamarkupfalse% |
24991 | 953 |
\ assoc\ {\isacharbrackleft}symmetric{\isacharbrackright}\ neutl\ invl\ \isacommand{have}\isamarkupfalse% |
25200 | 954 |
\ {\isachardoublequoteopen}x{\isasymdiv}\ {\isasymotimes}\ {\isacharparenleft}x\ {\isasymotimes}\ {\isasymone}{\isacharparenright}\ {\isacharequal}\ x{\isasymdiv}\ {\isasymotimes}\ x{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse% |
24991 | 955 |
\ simp\isanewline |
28566 | 956 |
\ \ \isacommand{with}\isamarkupfalse% |
24991 | 957 |
\ left{\isacharunderscore}cancel\ \isacommand{show}\isamarkupfalse% |
25200 | 958 |
\ {\isachardoublequoteopen}x\ {\isasymotimes}\ {\isasymone}\ {\isacharequal}\ x{\isachardoublequoteclose}\ \isacommand{by}\isamarkupfalse% |
24991 | 959 |
\ simp\isanewline |
28566 | 960 |
\isacommand{qed}\isamarkupfalse% |
24991 | 961 |
% |
28566 | 962 |
\endisatagquote |
963 |
{\isafoldquote}% |
|
24991 | 964 |
% |
28566 | 965 |
\isadelimquote |
24991 | 966 |
% |
28566 | 967 |
\endisadelimquote |
24991 | 968 |
% |
969 |
\begin{isamarkuptext}% |
|
30227 | 970 |
The logical proof is carried out on the locale level. |
28947
ac1a14b5a085
unfold_locales is default method - no need for explicit references
haftmann
parents:
28727
diff
changeset
|
971 |
Afterwards it is propagated |
24991 | 972 |
to the type system, making \isa{group} an instance of |
25247 | 973 |
\isa{monoid} by adding an additional edge |
974 |
to the graph of subclass relations |
|
975 |
(cf.\ \figref{fig:subclass}). |
|
976 |
||
977 |
\begin{figure}[htbp] |
|
978 |
\begin{center} |
|
979 |
\small |
|
980 |
\unitlength 0.6mm |
|
981 |
\begin{picture}(40,60)(0,0) |
|
982 |
\put(20,60){\makebox(0,0){\isa{semigroup}}} |
|
983 |
\put(20,40){\makebox(0,0){\isa{monoidl}}} |
|
984 |
\put(00,20){\makebox(0,0){\isa{monoid}}} |
|
985 |
\put(40,00){\makebox(0,0){\isa{group}}} |
|
986 |
\put(20,55){\vector(0,-1){10}} |
|
987 |
\put(15,35){\vector(-1,-1){10}} |
|
988 |
\put(25,35){\vector(1,-3){10}} |
|
989 |
\end{picture} |
|
990 |
\hspace{8em} |
|
991 |
\begin{picture}(40,60)(0,0) |
|
992 |
\put(20,60){\makebox(0,0){\isa{semigroup}}} |
|
993 |
\put(20,40){\makebox(0,0){\isa{monoidl}}} |
|
994 |
\put(00,20){\makebox(0,0){\isa{monoid}}} |
|
995 |
\put(40,00){\makebox(0,0){\isa{group}}} |
|
996 |
\put(20,55){\vector(0,-1){10}} |
|
997 |
\put(15,35){\vector(-1,-1){10}} |
|
998 |
\put(05,15){\vector(3,-1){30}} |
|
999 |
\end{picture} |
|
1000 |
\caption{Subclass relationship of monoids and groups: |
|
1001 |
before and after establishing the relationship |
|
30227 | 1002 |
\isa{group\ {\isasymsubseteq}\ monoid}; transitive edges are left out.} |
25247 | 1003 |
\label{fig:subclass} |
1004 |
\end{center} |
|
1005 |
\end{figure} |
|
30227 | 1006 |
|
25247 | 1007 |
For illustration, a derived definition |
24991 | 1008 |
in \isa{group} which uses \isa{pow{\isacharunderscore}nat}:% |
1009 |
\end{isamarkuptext}% |
|
1010 |
\isamarkuptrue% |
|
28565 | 1011 |
% |
1012 |
\isadelimquote |
|
1013 |
% |
|
1014 |
\endisadelimquote |
|
1015 |
% |
|
1016 |
\isatagquote |
|
1017 |
\isacommand{definition}\isamarkupfalse% |
|
1018 |
\ {\isacharparenleft}\isakeyword{in}\ group{\isacharparenright}\ pow{\isacharunderscore}int\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}int\ {\isasymRightarrow}\ {\isasymalpha}\ {\isasymRightarrow}\ {\isasymalpha}{\isachardoublequoteclose}\ \isakeyword{where}\isanewline |
|
1019 |
\ \ {\isachardoublequoteopen}pow{\isacharunderscore}int\ k\ x\ {\isacharequal}\ {\isacharparenleft}if\ k\ {\isachargreater}{\isacharequal}\ {\isadigit{0}}\isanewline |
|
1020 |
\ \ \ \ then\ pow{\isacharunderscore}nat\ {\isacharparenleft}nat\ k{\isacharparenright}\ x\isanewline |
|
1021 |
\ \ \ \ else\ {\isacharparenleft}pow{\isacharunderscore}nat\ {\isacharparenleft}nat\ {\isacharparenleft}{\isacharminus}\ k{\isacharparenright}{\isacharparenright}\ x{\isacharparenright}{\isasymdiv}{\isacharparenright}{\isachardoublequoteclose}% |
|
1022 |
\endisatagquote |
|
1023 |
{\isafoldquote}% |
|
1024 |
% |
|
1025 |
\isadelimquote |
|
1026 |
% |
|
1027 |
\endisadelimquote |
|
1028 |
% |
|
24991 | 1029 |
\begin{isamarkuptext}% |
25247 | 1030 |
\noindent yields the global definition of |
24991 | 1031 |
\isa{{\isachardoublequote}pow{\isacharunderscore}int\ {\isasymColon}\ int\ {\isasymRightarrow}\ {\isasymalpha}{\isasymColon}group\ {\isasymRightarrow}\ {\isasymalpha}{\isasymColon}group{\isachardoublequote}} |
1032 |
with the corresponding theorem \isa{pow{\isacharunderscore}int\ k\ x\ {\isacharequal}\ {\isacharparenleft}if\ {\isadigit{0}}\ {\isasymle}\ k\ then\ pow{\isacharunderscore}nat\ {\isacharparenleft}nat\ k{\isacharparenright}\ x\ else\ {\isacharparenleft}pow{\isacharunderscore}nat\ {\isacharparenleft}nat\ {\isacharparenleft}{\isacharminus}\ k{\isacharparenright}{\isacharparenright}\ x{\isacharparenright}{\isasymdiv}{\isacharparenright}}.% |
|
1033 |
\end{isamarkuptext}% |
|
1034 |
\isamarkuptrue% |
|
1035 |
% |
|
25868 | 1036 |
\isamarkupsubsection{A note on syntax% |
1037 |
} |
|
1038 |
\isamarkuptrue% |
|
1039 |
% |
|
1040 |
\begin{isamarkuptext}% |
|
1041 |
As a commodity, class context syntax allows to refer |
|
27507 | 1042 |
to local class operations and their global counterparts |
25868 | 1043 |
uniformly; type inference resolves ambiguities. For example:% |
1044 |
\end{isamarkuptext}% |
|
1045 |
\isamarkuptrue% |
|
28565 | 1046 |
% |
1047 |
\isadelimquote |
|
1048 |
% |
|
1049 |
\endisadelimquote |
|
1050 |
% |
|
1051 |
\isatagquote |
|
25868 | 1052 |
\isacommand{context}\isamarkupfalse% |
1053 |
\ semigroup\isanewline |
|
1054 |
\isakeyword{begin}\isanewline |
|
1055 |
\isanewline |
|
1056 |
\isacommand{term}\isamarkupfalse% |
|
1057 |
\ {\isachardoublequoteopen}x\ {\isasymotimes}\ y{\isachardoublequoteclose}\ % |
|
1058 |
\isamarkupcmt{example 1% |
|
1059 |
} |
|
1060 |
\isanewline |
|
1061 |
\isacommand{term}\isamarkupfalse% |
|
1062 |
\ {\isachardoublequoteopen}{\isacharparenleft}x{\isasymColon}nat{\isacharparenright}\ {\isasymotimes}\ y{\isachardoublequoteclose}\ % |
|
1063 |
\isamarkupcmt{example 2% |
|
1064 |
} |
|
1065 |
\isanewline |
|
1066 |
\isanewline |
|
1067 |
\isacommand{end}\isamarkupfalse% |
|
1068 |
\isanewline |
|
1069 |
\isanewline |
|
1070 |
\isacommand{term}\isamarkupfalse% |
|
1071 |
\ {\isachardoublequoteopen}x\ {\isasymotimes}\ y{\isachardoublequoteclose}\ % |
|
1072 |
\isamarkupcmt{example 3% |
|
1073 |
} |
|
1074 |
% |
|
28565 | 1075 |
\endisatagquote |
1076 |
{\isafoldquote}% |
|
1077 |
% |
|
1078 |
\isadelimquote |
|
1079 |
% |
|
1080 |
\endisadelimquote |
|
1081 |
% |
|
25868 | 1082 |
\begin{isamarkuptext}% |
1083 |
\noindent Here in example 1, the term refers to the local class operation |
|
1084 |
\isa{mult\ {\isacharbrackleft}{\isasymalpha}{\isacharbrackright}}, whereas in example 2 the type constraint |
|
1085 |
enforces the global class operation \isa{mult\ {\isacharbrackleft}nat{\isacharbrackright}}. |
|
1086 |
In the global context in example 3, the reference is |
|
1087 |
to the polymorphic global class operation \isa{mult\ {\isacharbrackleft}{\isacharquery}{\isasymalpha}\ {\isasymColon}\ semigroup{\isacharbrackright}}.% |
|
1088 |
\end{isamarkuptext}% |
|
1089 |
\isamarkuptrue% |
|
1090 |
% |
|
29705 | 1091 |
\isamarkupsection{Further issues% |
1092 |
} |
|
1093 |
\isamarkuptrue% |
|
1094 |
% |
|
1095 |
\isamarkupsubsection{Type classes and code generation% |
|
20967 | 1096 |
} |
1097 |
\isamarkuptrue% |
|
1098 |
% |
|
1099 |
\begin{isamarkuptext}% |
|
22317 | 1100 |
Turning back to the first motivation for type classes, |
1101 |
namely overloading, it is obvious that overloading |
|
28565 | 1102 |
stemming from \hyperlink{command.class}{\mbox{\isa{\isacommand{class}}}} statements and |
1103 |
\hyperlink{command.instantiation}{\mbox{\isa{\isacommand{instantiation}}}} |
|
25533 | 1104 |
targets naturally maps to Haskell type classes. |
22317 | 1105 |
The code generator framework \cite{isabelle-codegen} |
1106 |
takes this into account. Concerning target languages |
|
1107 |
lacking type classes (e.g.~SML), type classes |
|
1108 |
are implemented by explicit dictionary construction. |
|
28565 | 1109 |
As example, let's go back to the power function:% |
20967 | 1110 |
\end{isamarkuptext}% |
1111 |
\isamarkuptrue% |
|
28565 | 1112 |
% |
1113 |
\isadelimquote |
|
1114 |
% |
|
1115 |
\endisadelimquote |
|
1116 |
% |
|
1117 |
\isatagquote |
|
1118 |
\isacommand{definition}\isamarkupfalse% |
|
1119 |
\ example\ {\isacharcolon}{\isacharcolon}\ int\ \isakeyword{where}\isanewline |
|
1120 |
\ \ {\isachardoublequoteopen}example\ {\isacharequal}\ pow{\isacharunderscore}int\ {\isadigit{1}}{\isadigit{0}}\ {\isacharparenleft}{\isacharminus}{\isadigit{2}}{\isacharparenright}{\isachardoublequoteclose}% |
|
1121 |
\endisatagquote |
|
1122 |
{\isafoldquote}% |
|
1123 |
% |
|
1124 |
\isadelimquote |
|
1125 |
% |
|
1126 |
\endisadelimquote |
|
1127 |
% |
|
20967 | 1128 |
\begin{isamarkuptext}% |
22317 | 1129 |
\noindent This maps to Haskell as:% |
20967 | 1130 |
\end{isamarkuptext}% |
1131 |
\isamarkuptrue% |
|
28540 | 1132 |
% |
28565 | 1133 |
\isadelimquote |
28540 | 1134 |
% |
28565 | 1135 |
\endisadelimquote |
28540 | 1136 |
% |
28565 | 1137 |
\isatagquote |
28540 | 1138 |
% |
20967 | 1139 |
\begin{isamarkuptext}% |
28727 | 1140 |
\isatypewriter% |
28540 | 1141 |
\noindent% |
28714 | 1142 |
\hspace*{0pt}module Example where {\char123}\\ |
1143 |
\hspace*{0pt}\\ |
|
1144 |
\hspace*{0pt}\\ |
|
30121 | 1145 |
\hspace*{0pt}data Nat = Zero{\char95}nat | Suc Nat;\\ |
28714 | 1146 |
\hspace*{0pt}\\ |
1147 |
\hspace*{0pt}nat{\char95}aux ::~Integer -> Nat -> Nat;\\ |
|
1148 |
\hspace*{0pt}nat{\char95}aux i n = (if i <= 0 then n else nat{\char95}aux (i - 1) (Suc n));\\ |
|
1149 |
\hspace*{0pt}\\ |
|
1150 |
\hspace*{0pt}nat ::~Integer -> Nat;\\ |
|
1151 |
\hspace*{0pt}nat i = nat{\char95}aux i Zero{\char95}nat;\\ |
|
1152 |
\hspace*{0pt}\\ |
|
1153 |
\hspace*{0pt}class Semigroup a where {\char123}\\ |
|
1154 |
\hspace*{0pt} ~mult ::~a -> a -> a;\\ |
|
1155 |
\hspace*{0pt}{\char125};\\ |
|
1156 |
\hspace*{0pt}\\ |
|
1157 |
\hspace*{0pt}class (Semigroup a) => Monoidl a where {\char123}\\ |
|
1158 |
\hspace*{0pt} ~neutral ::~a;\\ |
|
1159 |
\hspace*{0pt}{\char125};\\ |
|
1160 |
\hspace*{0pt}\\ |
|
1161 |
\hspace*{0pt}class (Monoidl a) => Monoid a where {\char123}\\ |
|
1162 |
\hspace*{0pt}{\char125};\\ |
|
1163 |
\hspace*{0pt}\\ |
|
1164 |
\hspace*{0pt}class (Monoid a) => Group a where {\char123}\\ |
|
1165 |
\hspace*{0pt} ~inverse ::~a -> a;\\ |
|
1166 |
\hspace*{0pt}{\char125};\\ |
|
1167 |
\hspace*{0pt}\\ |
|
1168 |
\hspace*{0pt}inverse{\char95}int ::~Integer -> Integer;\\ |
|
1169 |
\hspace*{0pt}inverse{\char95}int i = negate i;\\ |
|
1170 |
\hspace*{0pt}\\ |
|
1171 |
\hspace*{0pt}neutral{\char95}int ::~Integer;\\ |
|
1172 |
\hspace*{0pt}neutral{\char95}int = 0;\\ |
|
1173 |
\hspace*{0pt}\\ |
|
1174 |
\hspace*{0pt}mult{\char95}int ::~Integer -> Integer -> Integer;\\ |
|
1175 |
\hspace*{0pt}mult{\char95}int i j = i + j;\\ |
|
1176 |
\hspace*{0pt}\\ |
|
1177 |
\hspace*{0pt}instance Semigroup Integer where {\char123}\\ |
|
1178 |
\hspace*{0pt} ~mult = mult{\char95}int;\\ |
|
1179 |
\hspace*{0pt}{\char125};\\ |
|
1180 |
\hspace*{0pt}\\ |
|
1181 |
\hspace*{0pt}instance Monoidl Integer where {\char123}\\ |
|
1182 |
\hspace*{0pt} ~neutral = neutral{\char95}int;\\ |
|
1183 |
\hspace*{0pt}{\char125};\\ |
|
1184 |
\hspace*{0pt}\\ |
|
1185 |
\hspace*{0pt}instance Monoid Integer where {\char123}\\ |
|
1186 |
\hspace*{0pt}{\char125};\\ |
|
1187 |
\hspace*{0pt}\\ |
|
1188 |
\hspace*{0pt}instance Group Integer where {\char123}\\ |
|
1189 |
\hspace*{0pt} ~inverse = inverse{\char95}int;\\ |
|
1190 |
\hspace*{0pt}{\char125};\\ |
|
1191 |
\hspace*{0pt}\\ |
|
28947
ac1a14b5a085
unfold_locales is default method - no need for explicit references
haftmann
parents:
28727
diff
changeset
|
1192 |
\hspace*{0pt}pow{\char95}nat ::~forall a.~(Monoid a) => Nat -> a -> a;\\ |
28714 | 1193 |
\hspace*{0pt}pow{\char95}nat Zero{\char95}nat x = neutral;\\ |
1194 |
\hspace*{0pt}pow{\char95}nat (Suc n) x = mult x (pow{\char95}nat n x);\\ |
|
1195 |
\hspace*{0pt}\\ |
|
28947
ac1a14b5a085
unfold_locales is default method - no need for explicit references
haftmann
parents:
28727
diff
changeset
|
1196 |
\hspace*{0pt}pow{\char95}int ::~forall a.~(Group a) => Integer -> a -> a;\\ |
28714 | 1197 |
\hspace*{0pt}pow{\char95}int k x =\\ |
1198 |
\hspace*{0pt} ~(if 0 <= k then pow{\char95}nat (nat k) x\\ |
|
1199 |
\hspace*{0pt} ~~~else inverse (pow{\char95}nat (nat (negate k)) x));\\ |
|
1200 |
\hspace*{0pt}\\ |
|
1201 |
\hspace*{0pt}example ::~Integer;\\ |
|
1202 |
\hspace*{0pt}example = pow{\char95}int 10 (-2);\\ |
|
1203 |
\hspace*{0pt}\\ |
|
1204 |
\hspace*{0pt}{\char125}% |
|
22317 | 1205 |
\end{isamarkuptext}% |
1206 |
\isamarkuptrue% |
|
28540 | 1207 |
% |
28565 | 1208 |
\endisatagquote |
1209 |
{\isafoldquote}% |
|
28540 | 1210 |
% |
28565 | 1211 |
\isadelimquote |
28540 | 1212 |
% |
28565 | 1213 |
\endisadelimquote |
28540 | 1214 |
% |
22317 | 1215 |
\begin{isamarkuptext}% |
28540 | 1216 |
\noindent The whole code in SML with explicit dictionary passing:% |
20967 | 1217 |
\end{isamarkuptext}% |
1218 |
\isamarkuptrue% |
|
1219 |
% |
|
28565 | 1220 |
\isadelimquote |
28540 | 1221 |
% |
28565 | 1222 |
\endisadelimquote |
28540 | 1223 |
% |
28565 | 1224 |
\isatagquote |
28540 | 1225 |
% |
1226 |
\begin{isamarkuptext}% |
|
28727 | 1227 |
\isatypewriter% |
28540 | 1228 |
\noindent% |
28714 | 1229 |
\hspace*{0pt}structure Example = \\ |
1230 |
\hspace*{0pt}struct\\ |
|
1231 |
\hspace*{0pt}\\ |
|
30121 | 1232 |
\hspace*{0pt}datatype nat = Zero{\char95}nat | Suc of nat;\\ |
28714 | 1233 |
\hspace*{0pt}\\ |
1234 |
\hspace*{0pt}fun nat{\char95}aux i n =\\ |
|
28947
ac1a14b5a085
unfold_locales is default method - no need for explicit references
haftmann
parents:
28727
diff
changeset
|
1235 |
\hspace*{0pt} ~(if IntInf.<= (i,~(0 :~IntInf.int)) then n\\ |
ac1a14b5a085
unfold_locales is default method - no need for explicit references
haftmann
parents:
28727
diff
changeset
|
1236 |
\hspace*{0pt} ~~~else nat{\char95}aux (IntInf.- (i,~(1 :~IntInf.int))) (Suc n));\\ |
28714 | 1237 |
\hspace*{0pt}\\ |
1238 |
\hspace*{0pt}fun nat i = nat{\char95}aux i Zero{\char95}nat;\\ |
|
1239 |
\hspace*{0pt}\\ |
|
1240 |
\hspace*{0pt}type 'a semigroup = {\char123}mult :~'a -> 'a -> 'a{\char125};\\ |
|
1241 |
\hspace*{0pt}fun mult (A{\char95}:'a semigroup) = {\char35}mult A{\char95};\\ |
|
1242 |
\hspace*{0pt}\\ |
|
1243 |
\hspace*{0pt}type 'a monoidl =\\ |
|
28947
ac1a14b5a085
unfold_locales is default method - no need for explicit references
haftmann
parents:
28727
diff
changeset
|
1244 |
\hspace*{0pt} ~{\char123}Classes{\char95}{\char95}semigroup{\char95}monoidl :~'a semigroup,~neutral :~'a{\char125};\\ |
28714 | 1245 |
\hspace*{0pt}fun semigroup{\char95}monoidl (A{\char95}:'a monoidl) = {\char35}Classes{\char95}{\char95}semigroup{\char95}monoidl A{\char95};\\ |
1246 |
\hspace*{0pt}fun neutral (A{\char95}:'a monoidl) = {\char35}neutral A{\char95};\\ |
|
1247 |
\hspace*{0pt}\\ |
|
1248 |
\hspace*{0pt}type 'a monoid = {\char123}Classes{\char95}{\char95}monoidl{\char95}monoid :~'a monoidl{\char125};\\ |
|
1249 |
\hspace*{0pt}fun monoidl{\char95}monoid (A{\char95}:'a monoid) = {\char35}Classes{\char95}{\char95}monoidl{\char95}monoid A{\char95};\\ |
|
1250 |
\hspace*{0pt}\\ |
|
28947
ac1a14b5a085
unfold_locales is default method - no need for explicit references
haftmann
parents:
28727
diff
changeset
|
1251 |
\hspace*{0pt}type 'a group = {\char123}Classes{\char95}{\char95}monoid{\char95}group :~'a monoid,~inverse :~'a -> 'a{\char125};\\ |
28714 | 1252 |
\hspace*{0pt}fun monoid{\char95}group (A{\char95}:'a group) = {\char35}Classes{\char95}{\char95}monoid{\char95}group A{\char95};\\ |
1253 |
\hspace*{0pt}fun inverse (A{\char95}:'a group) = {\char35}inverse A{\char95};\\ |
|
1254 |
\hspace*{0pt}\\ |
|
1255 |
\hspace*{0pt}fun inverse{\char95}int i = IntInf.{\char126}~i;\\ |
|
1256 |
\hspace*{0pt}\\ |
|
29297 | 1257 |
\hspace*{0pt}val neutral{\char95}int :~IntInf.int = (0 :~IntInf.int)\\ |
28714 | 1258 |
\hspace*{0pt}\\ |
28947
ac1a14b5a085
unfold_locales is default method - no need for explicit references
haftmann
parents:
28727
diff
changeset
|
1259 |
\hspace*{0pt}fun mult{\char95}int i j = IntInf.+ (i,~j);\\ |
28714 | 1260 |
\hspace*{0pt}\\ |
1261 |
\hspace*{0pt}val semigroup{\char95}int = {\char123}mult = mult{\char95}int{\char125}~:~IntInf.int semigroup;\\ |
|
1262 |
\hspace*{0pt}\\ |
|
1263 |
\hspace*{0pt}val monoidl{\char95}int =\\ |
|
28947
ac1a14b5a085
unfold_locales is default method - no need for explicit references
haftmann
parents:
28727
diff
changeset
|
1264 |
\hspace*{0pt} ~{\char123}Classes{\char95}{\char95}semigroup{\char95}monoidl = semigroup{\char95}int,~neutral = neutral{\char95}int{\char125}~:\\ |
28714 | 1265 |
\hspace*{0pt} ~IntInf.int monoidl;\\ |
1266 |
\hspace*{0pt}\\ |
|
1267 |
\hspace*{0pt}val monoid{\char95}int = {\char123}Classes{\char95}{\char95}monoidl{\char95}monoid = monoidl{\char95}int{\char125}~:\\ |
|
1268 |
\hspace*{0pt} ~IntInf.int monoid;\\ |
|
1269 |
\hspace*{0pt}\\ |
|
1270 |
\hspace*{0pt}val group{\char95}int =\\ |
|
28947
ac1a14b5a085
unfold_locales is default method - no need for explicit references
haftmann
parents:
28727
diff
changeset
|
1271 |
\hspace*{0pt} ~{\char123}Classes{\char95}{\char95}monoid{\char95}group = monoid{\char95}int,~inverse = inverse{\char95}int{\char125}~:\\ |
28714 | 1272 |
\hspace*{0pt} ~IntInf.int group;\\ |
1273 |
\hspace*{0pt}\\ |
|
1274 |
\hspace*{0pt}fun pow{\char95}nat A{\char95}~Zero{\char95}nat x = neutral (monoidl{\char95}monoid A{\char95})\\ |
|
1275 |
\hspace*{0pt} ~| pow{\char95}nat A{\char95}~(Suc n) x =\\ |
|
1276 |
\hspace*{0pt} ~~~mult ((semigroup{\char95}monoidl o monoidl{\char95}monoid) A{\char95}) x (pow{\char95}nat A{\char95}~n x);\\ |
|
1277 |
\hspace*{0pt}\\ |
|
1278 |
\hspace*{0pt}fun pow{\char95}int A{\char95}~k x =\\ |
|
28947
ac1a14b5a085
unfold_locales is default method - no need for explicit references
haftmann
parents:
28727
diff
changeset
|
1279 |
\hspace*{0pt} ~(if IntInf.<= ((0 :~IntInf.int),~k)\\ |
28714 | 1280 |
\hspace*{0pt} ~~~then pow{\char95}nat (monoid{\char95}group A{\char95}) (nat k) x\\ |
1281 |
\hspace*{0pt} ~~~else inverse A{\char95}~(pow{\char95}nat (monoid{\char95}group A{\char95}) (nat (IntInf.{\char126}~k)) x));\\ |
|
1282 |
\hspace*{0pt}\\ |
|
1283 |
\hspace*{0pt}val example :~IntInf.int =\\ |
|
29297 | 1284 |
\hspace*{0pt} ~pow{\char95}int group{\char95}int (10 :~IntInf.int) ({\char126}2 :~IntInf.int)\\ |
28714 | 1285 |
\hspace*{0pt}\\ |
28947
ac1a14b5a085
unfold_locales is default method - no need for explicit references
haftmann
parents:
28727
diff
changeset
|
1286 |
\hspace*{0pt}end;~(*struct Example*)% |
28540 | 1287 |
\end{isamarkuptext}% |
1288 |
\isamarkuptrue% |
|
1289 |
% |
|
28565 | 1290 |
\endisatagquote |
1291 |
{\isafoldquote}% |
|
28540 | 1292 |
% |
28565 | 1293 |
\isadelimquote |
28540 | 1294 |
% |
28565 | 1295 |
\endisadelimquote |
28540 | 1296 |
% |
29705 | 1297 |
\isamarkupsubsection{Inspecting the type class universe% |
1298 |
} |
|
1299 |
\isamarkuptrue% |
|
1300 |
% |
|
1301 |
\begin{isamarkuptext}% |
|
1302 |
To facilitate orientation in complex subclass structures, |
|
1303 |
two diagnostics commands are provided: |
|
1304 |
||
1305 |
\begin{description} |
|
1306 |
||
1307 |
\item[\hyperlink{command.print-classes}{\mbox{\isa{\isacommand{print{\isacharunderscore}classes}}}}] print a list of all classes |
|
1308 |
together with associated operations etc. |
|
1309 |
||
1310 |
\item[\hyperlink{command.class-deps}{\mbox{\isa{\isacommand{class{\isacharunderscore}deps}}}}] visualizes the subclass relation |
|
1311 |
between all classes as a Hasse diagram. |
|
1312 |
||
1313 |
\end{description}% |
|
1314 |
\end{isamarkuptext}% |
|
1315 |
\isamarkuptrue% |
|
1316 |
% |
|
20967 | 1317 |
\isadelimtheory |
1318 |
% |
|
1319 |
\endisadelimtheory |
|
1320 |
% |
|
1321 |
\isatagtheory |
|
1322 |
\isacommand{end}\isamarkupfalse% |
|
1323 |
% |
|
1324 |
\endisatagtheory |
|
1325 |
{\isafoldtheory}% |
|
1326 |
% |
|
1327 |
\isadelimtheory |
|
1328 |
% |
|
1329 |
\endisadelimtheory |
|
1330 |
\isanewline |
|
1331 |
\end{isabellebody}% |
|
1332 |
%%% Local Variables: |
|
1333 |
%%% mode: latex |
|
1334 |
%%% TeX-master: "root" |
|
1335 |
%%% End: |