[Haskell-beginners] WWAAA... I hate monads
Daniel Carrera
daniel.carrera at theingots.org
Wed Apr 22 09:17:03 EDT 2009
Jason Dusek wrote:
> Actually, the third law is:
>
> (m >>= f) >>= g == m >>= (\x -> f x >>= g)
Yeah. I just saw that in the tutorial. And it actually makes more sense
that way (esp after reading some of the tutorial):
1) A "computation" is something that may have a result.
2) In "m >>= f", m is a computation and f is a function that takes a
value and returns a computation. >>= takes the output of m and makes it
the input of f.
3) Therefore, the value of "m >>= f" is a computation.
4) Because "m >>= f" is a computation, it can be the left parameter of
another >>=, as in "(m >>= f) >>= g".
5) If "x" is a value then "f x" is a computation. Thus, "f x" can be the
left parameter of >>=, as in "f x >>= g", and the result of that is a
computation.
6) Therefore, (\x -> f x >>= g) is a function that takes a value ("x")
and returns a computation, so it can be the right parameter of >>=.
I think I get it (at least this part).
Cheers,
Daniel.
More information about the Beginners
mailing list