
23 Feb
2013
23 Feb
'13
10:58 a.m.
On Sat, Feb 23, 2013 at 7:27 AM, xiao Ling
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 ), but without unwrapping the value from the monad?
In addition to the fine points that Brent and Brandon have already made, I observe that there seems to be a reservation about "unwrapping the value from the monad", which I don't get.
Your code is equivalent to h = \mx my -> do { x <- mx; y <- my; return $ x+y; }, which, I suspect, doesn't go well with you because of the "unwrapping". Or are you aiming at syntactic compositionality, i.e. point-free style? Once you've hacked Haskell enough, you just reach for the liftM2 combinator and write h = liftM2 (+). -- Kim-Ee