-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheqInstance.hs
More file actions
54 lines (40 loc) · 1.08 KB
/
eqInstance.hs
File metadata and controls
54 lines (40 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
module EqExercise where
data TisAnInteger = TisAn Integer
instance Eq TisAnInteger where
(==) (TisAn a) (TisAn a') = a == a'
data TwoIntegers =
Two Integer Integer
instance Eq TwoIntegers where
(==) (Two a a')
(Two a'' a'') =
a == a'' && a' == a'''
data StringOrInt =
TisAnInt Int
| TisAString String
instance Eq StringOrInt where
(==) (TisAnInt a) (TisAnInt a') = a == a'
(==) (TisAString a) (TisAString a') = a == a'
(==) _ _ = False
data Pair a =
Pair a a
instance Eq a => Eq (Pair a) where
(==) (Pair a a') (Pair a'' a''') =
a == a'' && a' == a'''
data Tuple a b =
Tuple a b
instance (Eq a, Eq b) => Eq (Tuple a b) where
(==) (Tuple a b) (Tuple a' b') =
a == a' && b == b'
data Which a =
ThisOne a | ThatOne a
instance Eq a => Eq a where
(==) (ThisOne a) (ThisOne a') = a == a'
(==) (ThatOne a) (ThatOne a') = a == a'
(==) _ _ = False
data EitherOr a b =
Hello a
| Goodbye b
instance (Eq a, Eq b) => Eq (EitherOr a b) where
(==) (Hello a) (Hello a') = a == a'
(==) (Goodbye b) (Goodbye b') = b == b'
(==) _ _ = False