Last active
February 20, 2019 20:22
-
-
Save willbasky/b41392b06c77cd3294c8226408e61e96 to your computer and use it in GitHub Desktop.
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
Eq Instances | |
1. | |
> data TisAnInteger = TisAn Integer | |
> instance Eq TisAnInteger where | |
> TisAn n == TisAn n' = n == n' | |
2. | |
> data TwoIntegers = Two Integer Integer | |
> instance Eq TwoIntegers where | |
> Two n m == Two n' m' = (n == n') && (m == m') | |
3. | |
> data StringOrInt = TisAnInt Int | TisAString String | |
> instance Eq StringOrInt where | |
> TisAnInt n == TisAnInt n' = n == n' | |
> TisAString str == TisAString str' = str == str' | |
4. | |
> data Pair a = Pair a a | |
> instance Eq a => Eq (Pair a) where | |
> Pair a _ == Pair a' _ = a == a' | |
5. | |
> data Tuple a b = Tuple a b | |
> instance (Eq a, Eq b) => Eq (Pair a b) where | |
> Tuple a b == Tuple a' b' = (a == a') && (b == b') | |
6. | |
> data Which a = ThisOne a | ThatOne a | |
> instance Eq a => Eq (Which a) where | |
> ThisOne a == ThisOne a' = a == a' | |
> ThatOne a == ThatOne a' = a == a' | |
7. | |
> 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' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment