Created
February 23, 2013 13:02
-
-
Save WillNess/5019652 to your computer and use it in GitHub Desktop.
How do you define a function of signature h :: M Int -> M Int -> M Int so that h (M x) (M y) = M (x+y) without unwrapping the monad?
http://stackoverflow.com/questions/15035468/how-do-you-define-a-function-of-signature-h-m-int-m-int-m-int-so-that-h
This file contains hidden or 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
g x y = (return . (+x)) =<< y | |
= (=<<) (return . (+x)) y | |
= ((=<<) . (return .)) ((+) x) y | |
= (=<<) . (return .) . (+) $ x y | |
h mx my = mx >>= (\x -> | |
my >>= (\y -> | |
return (x+y) )) | |
h mx my = do x <- mx | |
y <- my | |
return (x+y) | |
h mx my = liftM2 (+) mx my |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment