8906
|
1 |
|
9146
|
2 |
header {* Semigroups *}
|
8906
|
3 |
|
9146
|
4 |
theory Semigroups = Main:
|
8890
|
5 |
|
8906
|
6 |
text {*
|
|
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
|
10140
|
10 |
--- i.e.\ abstractions over a single type argument @{typ 'a}. Class
|
8907
|
11 |
axioms typically contain polymorphic constants that depend on this
|
10140
|
12 |
type @{typ 'a}. These \emph{characteristic constants} behave like
|
|
13 |
operations associated with the ``carrier'' type @{typ 'a}.
|
8906
|
14 |
|
|
15 |
We illustrate these basic concepts by the following formulation of
|
|
16 |
semigroups.
|
9146
|
17 |
*}
|
8890
|
18 |
|
|
19 |
consts
|
10140
|
20 |
times :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<odot>" 70)
|
|
21 |
axclass semigroup < "term"
|
|
22 |
assoc: "(x \<odot> y) \<odot> z = x \<odot> (y \<odot> z)"
|
8906
|
23 |
|
|
24 |
text {*
|
10140
|
25 |
\noindent Above we have first declared a polymorphic constant @{text
|
|
26 |
"\<odot> \<Colon> 'a \<Rightarrow> 'a \<Rightarrow> 'a"} and then defined the class @{text semigroup} of
|
|
27 |
all types @{text \<tau>} such that @{text "\<odot> \<Colon> \<tau> \<Rightarrow> \<tau> \<Rightarrow> \<tau>"} is indeed an
|
|
28 |
associative operator. The @{text assoc} axiom contains exactly one
|
|
29 |
type variable, which is invisible in the above presentation, though.
|
|
30 |
Also note that free term variables (like @{term x}, @{term y}, @{term
|
|
31 |
z}) are allowed for user convenience --- conceptually all of these
|
|
32 |
are bound by outermost universal quantifiers.
|
8906
|
33 |
|
|
34 |
\medskip In general, type classes may be used to describe
|
10140
|
35 |
\emph{structures} with exactly one carrier @{typ 'a} and a fixed
|
8906
|
36 |
\emph{signature}. Different signatures require different classes.
|
10223
|
37 |
Below, class @{text plus_semigroup} represents semigroups
|
|
38 |
@{text "(\<tau>, \<oplus>\<^sup>\<tau>)"}, while the original @{text semigroup} would
|
|
39 |
correspond to semigroups of the form @{text "(\<tau>, \<odot>\<^sup>\<tau>)"}.
|
9146
|
40 |
*}
|
8906
|
41 |
|
|
42 |
consts
|
10140
|
43 |
plus :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<oplus>" 70)
|
|
44 |
axclass plus_semigroup < "term"
|
|
45 |
assoc: "(x \<oplus> y) \<oplus> z = x \<oplus> (y \<oplus> z)"
|
8890
|
46 |
|
8906
|
47 |
text {*
|
10140
|
48 |
\noindent Even if classes @{text plus_semigroup} and @{text
|
|
49 |
semigroup} both represent semigroups in a sense, they are certainly
|
|
50 |
not quite the same.
|
9146
|
51 |
*}
|
8890
|
52 |
|
9146
|
53 |
end |