9767
|
1 |
%
|
|
2 |
\begin{isabellebody}%
|
8906
|
3 |
%
|
|
4 |
\isamarkupheader{Semigroups}
|
9672
|
5 |
\isacommand{theory}\ Semigroups\ {\isacharequal}\ Main{\isacharcolon}%
|
8906
|
6 |
\begin{isamarkuptext}%
|
|
7 |
\medskip\noindent An axiomatic type class is simply a class of types
|
8907
|
8 |
that all meet certain properties, which are also called \emph{class
|
|
9 |
axioms}. Thus, type classes may be also understood as type predicates
|
|
10 |
--- i.e.\ abstractions over a single type argument $\alpha$. Class
|
|
11 |
axioms typically contain polymorphic constants that depend on this
|
|
12 |
type $\alpha$. These \emph{characteristic constants} behave like
|
|
13 |
operations associated with the ``carrier'' type $\alpha$.
|
8906
|
14 |
|
|
15 |
We illustrate these basic concepts by the following formulation of
|
|
16 |
semigroups.%
|
|
17 |
\end{isamarkuptext}%
|
8890
|
18 |
\isacommand{consts}\isanewline
|
9672
|
19 |
\ \ times\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a{\isachardoublequote}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequote}{\isasymOtimes}{\isachardoublequote}\ \isadigit{7}\isadigit{0}{\isacharparenright}\isanewline
|
8906
|
20 |
\isacommand{axclass}\isanewline
|
9665
|
21 |
\ \ semigroup\ {\isacharless}\ {\isachardoublequote}term{\isachardoublequote}\isanewline
|
9672
|
22 |
\ \ assoc{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}x\ {\isasymOtimes}\ y{\isacharparenright}\ {\isasymOtimes}\ z\ {\isacharequal}\ x\ {\isasymOtimes}\ {\isacharparenleft}y\ {\isasymOtimes}\ z{\isacharparenright}{\isachardoublequote}%
|
8906
|
23 |
\begin{isamarkuptext}%
|
|
24 |
\noindent Above we have first declared a polymorphic constant $\TIMES
|
|
25 |
:: \alpha \To \alpha \To \alpha$ and then defined the class
|
|
26 |
$semigroup$ of all types $\tau$ such that $\TIMES :: \tau \To \tau
|
|
27 |
\To \tau$ is indeed an associative operator. The $assoc$ axiom
|
|
28 |
contains exactly one type variable, which is invisible in the above
|
|
29 |
presentation, though. Also note that free term variables (like $x$,
|
|
30 |
$y$, $z$) are allowed for user convenience --- conceptually all of
|
|
31 |
these are bound by outermost universal quantifiers.
|
|
32 |
|
|
33 |
\medskip In general, type classes may be used to describe
|
|
34 |
\emph{structures} with exactly one carrier $\alpha$ and a fixed
|
|
35 |
\emph{signature}. Different signatures require different classes.
|
8907
|
36 |
Below, class $plus_semigroup$ represents semigroups of the form
|
|
37 |
$(\tau, \PLUS^\tau)$, while the original $semigroup$ would correspond
|
8906
|
38 |
to semigroups $(\tau, \TIMES^\tau)$.%
|
|
39 |
\end{isamarkuptext}%
|
|
40 |
\isacommand{consts}\isanewline
|
9672
|
41 |
\ \ plus\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a{\isachardoublequote}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequote}{\isasymOplus}{\isachardoublequote}\ \isadigit{7}\isadigit{0}{\isacharparenright}\isanewline
|
8890
|
42 |
\isacommand{axclass}\isanewline
|
9665
|
43 |
\ \ plus{\isacharunderscore}semigroup\ {\isacharless}\ {\isachardoublequote}term{\isachardoublequote}\isanewline
|
9672
|
44 |
\ \ assoc{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}x\ {\isasymOplus}\ y{\isacharparenright}\ {\isasymOplus}\ z\ {\isacharequal}\ x\ {\isasymOplus}\ {\isacharparenleft}y\ {\isasymOplus}\ z{\isacharparenright}{\isachardoublequote}%
|
8906
|
45 |
\begin{isamarkuptext}%
|
8907
|
46 |
\noindent Even if classes $plus_semigroup$ and $semigroup$ both
|
|
47 |
represent semigroups in a sense, they are certainly not quite the
|
|
48 |
same.%
|
8906
|
49 |
\end{isamarkuptext}%
|
9767
|
50 |
\isacommand{end}\end{isabellebody}%
|
9145
|
51 |
%%% Local Variables:
|
|
52 |
%%% mode: latex
|
|
53 |
%%% TeX-master: "root"
|
|
54 |
%%% End:
|