Created
May 18, 2015 11:41
-
-
Save edvakf/534fb10095dbc3003557 to your computer and use it in GitHub Desktop.
mymaybe.hs
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 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