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

xiao Ling lingxiao at seas.upenn.edu
Sat Feb 23 01:27:28 CET 2013

Hi All: 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?

 This question is from the article "Trivial Monad" found at
http://blog.sigfpe.com/2007/04/trivial-monad.html. The provided answer is

h x y = x >>= (\x -> g x y)

or equivalently ( in context of the article )

h :: M Int -> M Int -> M Int
h x y = bind ( \x-> g x y ) x

where g is

g :: Int -> W Int -> W Int
g x y = y >>= (return . (+x))

for the monad:

data M a = M a deriving Show

Now I am a little confused, how can you put x in g if it takes an Int as
first parameter but x is M Int?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130222/1e237638/attachment-0001.htm>

More information about the Beginners mailing list