(m >>= f) >>= g = m >>= (\x -> f x >>= g)
what’s different from f and \x->f x ??
I think they’re the same type a -> m b. but it seems that the second >>= at right side of equation treats the type of \x->f x as m b.
what’s going wrong?
The expressions
fand\x -> f xdo, for most purposes, mean the same thing. However, the scope of a lambda expression extends as far to the right as possible, i.e.m >>= (\x -> (f x >>= g)).If the types are
m :: m a,f :: a -> m b, andg :: b -> m c, then on the left we have(m >>= f) :: m b, and on the right we have(\x -> f x >>= g) :: a -> m c.So, the difference between the two expressions is just which order the
(>>=)operations are performed, much like the expressions1 + (2 + 3)and(1 + 2) + 3differ only in the order in which the additions are performed.The monad laws require that, like addition, the answer should be the same for both.