[Haskell-beginners] Hutton Ex 8.9.7
trent shipley
trent.shipley at gmail.com
Sat Sep 15 08:23:47 UTC 2018
I couldn't get close on my own.
From: https://github.com/pankajgodbole/hutton/blob/master/exercises.hs
{-
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20180915/6330b28a/attachment.html>
More information about the Beginners
mailing list