Created
July 25, 2016 03:15
-
-
Save mudphone/37e7574654608dbe83f89a7c9ac44e3b to your computer and use it in GitHub Desktop.
Typeclass instances
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Six where | |
data TisAnInteger = | |
TisAn Integer | |
instance Eq TisAnInteger where | |
(==) (TisAn x) (TisAn x') = | |
x == x' | |
data TwoIntegers = | |
Two Integer Integer | |
instance Eq TwoIntegers where | |
(==) (Two x y) (Two x' y') = | |
x == x' && y == y' | |
data StringOrInt = | |
TisAnInt Int | |
| TisAString String | |
instance Eq StringOrInt where | |
(==) (TisAnInt x) (TisAnInt x') = | |
x == x' | |
(==) (TisAString x) (TisAString x') = | |
x == x' | |
(==) _ _ = False | |
data Pair a = | |
Pair a a | |
instance Eq a => Eq (Pair a) where | |
(==) (Pair x y) (Pair x' y') = | |
x == x' && y == y' | |
data Tuple a b = | |
Tuple a b | |
instance (Eq a, Eq b) => Eq (Tuple a b) where | |
(==) (Tuple x y) (Tuple x' y') = | |
x == x' && y == y' | |
data Which a = | |
ThisOne a | |
| ThatOne a | |
instance Eq a => Eq (Which a) where | |
(==) (ThisOne x) (ThisOne x') = | |
x == x' | |
(==) (ThatOne x) (ThatOne x') = | |
x == x' | |
(==) _ _ = False | |
data EitherOr a b = | |
Hello a | |
| Goodbye b | |
instance (Eq a, Eq b) => Eq (EitherOr a b) where | |
(==) (Hello x) (Hello x') = | |
x == x' | |
(==) (Goodbye x) (Goodbye x') = | |
x == x' | |
(==) _ _ = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment