
Hi, I'm a functional programming newbie trying to get the hang of the concept of Monads, but one thing about bind puzzles me. Let's take an IO Monad-example: readLn >>= \i -> readLn >>= \j -> return (i + j) I fail to see how (\j -> return (i + j)) can know about the value of i. Isn't just the value of the previous readLn passed to \j -> return (i + j)? /Smalmatskungen

On Tue, 25 Jan 2005, [iso-8859-1] Simon Ulfsb�cker wrote:
Hi,
I'm a functional programming newbie trying to get the hang of the concept of Monads, but one thing about bind puzzles me. Let's take an IO Monad-example:
readLn >>= \i -> readLn >>= \j -> return (i + j)
I fail to see how (\j -> return (i + j)) can know about the value of i. Isn't just the value of the previous readLn passed to \j -> return (i + j)?
The expression means readLn >>= (\i -> (readLn >>= (\j -> return (i + j)))) That is the first readLn is combined with the function (\i -> (readLn >>= (\j -> return (i + j)))) which processes its input, in this case represented by the identifier i.
participants (2)
-
Henning Thielemann
-
Simon Ulfsbäcker