6 -- (x::A)->B is dependant functions
7 -- (x = y) A is equality in type A
10 -- For simplicity we may require decidable equality on the elements.
11 class {-(Eq a) =>-} SemiGroup a where
13 -- assocAdd :: (x::a)->(y::a)->(z::a)->
14 -- ((a+.b)+.c = a+.(b+.c)) a
16 class (SemiGroup a) => Monoid a where
18 -- leftZero :: (x::a) -> (zero +. x = x) a
20 class (Monoid a) => Group a where
24 -- leftNeg :: (x::a) -> (neg x +. x = zero) a
26 class (Group a) => AbelianGroup a
27 -- commAdd :: (x::a)->(y::a)-> (x+.y = y+.x) a
29 class (AbelianGroup a) => Ring a where
31 -- assocMul :: (x::a)->(y::a)->(z::a)->
32 -- ((a*.b)*.c = a*.(b*.c)) a
33 -- distrRingL :: (x::a)->(y::a)->(z::a)->
34 -- (x*.(y+.z) = x*.y +. x*.z)
35 -- distrRingR :: (x::a)->(y::a)->(z::a)->
36 -- ((y+.z)*.x = y*.x +. z*.x)
38 class (Ring a) => UnityRing a where
40 -- leftOne :: (x::a)->(one *. x = x) a
41 -- rightOne :: (x::a)->(x *. one = x) a
43 class (Ring a) => CommutativeRing a
44 -- commMul :: (x::a)->(y::a)-> (x*.y = y*.x) a
46 class (CommutativeRing a, UnityRing a) => IntegralDomain a
47 -- noZeroDiv :: (x::a)->(y::a)-> ( (x*.y = zero) a -> Either ((x=zero) a) ((y=zero) a) )
49 class (UnityRing a) => DivisionRing a where
53 -- leftinv :: (x::a) -> (inv x *. x = one) a
55 class (DivisionRing a, CommutativeRing a) => Field a
57 -- Every finite integral domain is a field.
59 -- Unique Factorization Domain
60 class (IntegralDomain a) => UFD a
61 -- every non-zero element has a unique factorization
63 -- Principal Ideal Domain
64 class (IntegralDomain a) => PID a
65 -- every ideal is a principal ideal
67 ---------------------------------------------------
70 instance SemiGroup [a] where
72 instance Monoid [a] where
76 instance SemiGroup Bool where
78 instance Monoid Bool where
80 instance Group Bool where
82 instance AbelianGroup Bool
83 instance Ring Bool where
85 instance CommutativeRing Bool
86 instance UnityRing Bool where
88 instance DivisionRing Bool where
92 instance SemiGroup Int where
94 instance Monoid Int where
96 instance Group Int where
98 instance AbelianGroup Int
99 instance Ring Int where
101 instance CommutativeRing Int
102 instance UnityRing Int where
106 instance SemiGroup Integer where
108 instance Monoid Integer where
110 instance Group Integer where
112 instance AbelianGroup Integer
113 instance Ring Integer where
115 instance CommutativeRing Integer
116 instance UnityRing Integer where
118 instance IntegralDomain Integer
121 -- A new data tupe is needed to do the instance declarations
122 data Q = Q Rational {-#STRICT#-} deriving (Eq, Ord)
123 instance Text Q where
126 showsType _ = showString "Q"
128 showsPrec n (Q p) = showsPrec n p
129 instance SemiGroup Q where
131 instance Monoid Q where
133 instance Group Q where
135 instance AbelianGroup Q
136 instance Ring Q where
138 instance CommutativeRing Q
139 instance UnityRing Q where
141 instance IntegralDomain Q
142 instance DivisionRing Q where
143 inv (Q x) = Q (recip x)