Created
April 4, 2017 02:54
-
-
Save LightAndLight/98854d6cf839c6e70ea13420484a9021 to your computer and use it in GitHub Desktop.
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
class Monad m where { | |
return : a -> m a; | |
bind : m a -> (a -> m b) -> m b | |
} | |
liftM2 : forall a b c m. Monad m => (a -> b -> c) -> m a -> m b -> m c | |
liftM2 f ma mb = bind ma (\a. bind mb (\b. return (f a b))) | |
data Maybe a = Nothing | Just a | |
instance Monad Maybe where { | |
return = Just; | |
bind ma f = case ma of { | |
Nothing -> Nothing; | |
Just a -> f a | |
} | |
} | |
and : Bool -> Bool -> Bool | |
and a b = case a of { | |
true -> b; | |
_ -> false | |
} | |
asdf = liftM2 and (Just true) Nothing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment