{-
7. Complete the following instance declarations:
instance Eq a => Eq (Maybe a) where
...
instance Eq a => Eq [a] where
...
-}
-- suggested answer
instance Eq a => Eq (Maybe a) where
-- Defines the (==) operation.
Nothing == Nothing = True
Just == Just = True
-- why isn't this Just a == Just a ?
-- My guess is that a and Just a are different types and can't be == in Haskell
_ == _ = False
instance Eq a => Eq [a] where
-- Defines the (==) operation.
[] == [] = True
[x] == [y] = x == y
(x:xs) == (y:ys) = x==y && xs==ys -- I assume this is implicitly recursive.
_ == _ = False