Skip to content

Instantly share code, notes, and snippets.

@vijaykiran
Created November 13, 2013 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vijaykiran/7450073 to your computer and use it in GitHub Desktop.
Save vijaykiran/7450073 to your computer and use it in GitHub Desktop.
Getting a hang of Haskell Types
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