Skip to content

Instantly share code, notes, and snippets.

@edvakf
Created May 18, 2015 11:41
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 edvakf/534fb10095dbc3003557 to your computer and use it in GitHub Desktop.
Save edvakf/534fb10095dbc3003557 to your computer and use it in GitHub Desktop.
mymaybe.hs
data MyMaybe a = MyNothing | MyJust a deriving (Show)
instance Functor MyMaybe where
fmap f MyNothing = MyNothing
fmap f (MyJust a) = MyJust (f a)
instance Applicative MyMaybe where
pure x = MyJust x
MyNothing <*> _ = MyNothing
_ <*> MyNothing = MyNothing
MyJust f <*> MyJust a = MyJust (f a)
instance Monad MyMaybe where
return = pure
MyNothing >>= _ = MyNothing
MyJust x >>= f = f x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment