Created
November 13, 2013 14:35
-
-
Save vijaykiran/7450073 to your computer and use it in GitHub Desktop.
Getting a hang of Haskell Types
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
data Perhaps a = Nil | Only a | |
instance (Eq a) => Eq (Perhaps a) where | |
Only x == Only y = x == y | |
Nil == Nil = True | |
instance (Show a) => Show (Perhaps a) where | |
show Nil = "Nil is Nothing" | |
show (Only x) = " It is Only " ++ show x | |
instance Functor Perhaps where | |
fmap f (Only x) = Only $ f x | |
fmap f Nil = Nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment