On Fri, Feb 22, 2013 at 7:27 PM, xiao Ling <lingxiao@seas.upenn.edu> wrote:
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?

Because it's a different "x".  Lemme rewrite it slightly:

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

All I did was replace the inner "x" with "w", to demonstrate that it has no relationship to the outer "x"; the \... -> syntax introduces new local bindings unrelated to any outside of it, in this case for "w" (or what he had "x", shadowing the original binding of "x" within the lambda).

--
brandon s allbery kf8nh                               sine nomine associates
allbery.b@gmail.com                                  ballbery@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net