[Haskell-beginners] Beginners Digest, Vol 56, Issue 33

Kim-Ee Yeoh ky3 at atamo.com
Sat Feb 23 16:58:55 CET 2013

On Sat, Feb 23, 2013 at 7:27 AM, xiao Ling <lingxiao at seas.upenn.edu> wrote:

>  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

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130223/01298f51/attachment.htm>

More information about the Beginners mailing list