Skip to content

Commit

Permalink
Complete redo of Eq instances exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
evturn committed Jan 20, 2018
1 parent 2ea42b8 commit a639897
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 57 deletions.
65 changes: 65 additions & 0 deletions 06/06.05-eq-instances.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
-- 1.
data TisAnInteger = TisAn Integer
deriving Show

instance Eq TisAnInteger where
(==) (TisAn x) (TisAn y) = x == y

-----------------------------------------------------------------------------
-- 2.
data TwoIntegers = Two Integer Integer
deriving Show

instance Eq TwoIntegers where
(==) (Two x y) (Two x' y') = x == x' && y == y'

-----------------------------------------------------------------------------
-- 3.
data StringOrInt = TisAnInt Int
| TisAString String
deriving Show

instance Eq StringOrInt where
(==) (TisAnInt x) (TisAnInt y) = x == y
(==) (TisAString x) (TisAString y) = x == y
(==) _ _ = False

-----------------------------------------------------------------------------
-- 4.
data Pair a = Pair a a
deriving Show

instance Eq a => Eq (Pair a) where
(==) (Pair x y) (Pair x' y') = x == x' && y == y'

-----------------------------------------------------------------------------
-- 5.
data Tuple a b = Tuple a b
deriving Show

instance (Eq a, Eq b) => Eq (Tuple a b) where
(==) (Tuple x y) (Tuple x' y') = x == x' && y == y'

-----------------------------------------------------------------------------
-- 6.
data Which a = ThisOne a
| ThatOne a
deriving Show

instance Eq a => Eq (Which a) where
(==) (ThisOne x) (ThisOne x') = x == x'
(==) (ThatOne x) (ThatOne x') = x == x'
(==) _ _ = False

-----------------------------------------------------------------------------
-- 7.
data EitherOr a b = Hello a
| Goodbye b
deriving Show

instance (Eq a, Eq b) => Eq (EitherOr a b) where
(==) (Hello x) (Hello x') = x == x'
(==) (Goodbye x) (Goodbye x') = x == x'
(==) _ _ = False


57 changes: 0 additions & 57 deletions 06/eq-instances.hs

This file was deleted.

0 comments on commit a639897

Please sign in to comment.