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