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