Skip to content

Instantly share code, notes, and snippets.

@LightAndLight
Created April 4, 2017 02:54
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 LightAndLight/98854d6cf839c6e70ea13420484a9021 to your computer and use it in GitHub Desktop.
Save LightAndLight/98854d6cf839c6e70ea13420484a9021 to your computer and use it in GitHub Desktop.
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