[Haskell-cafe] Newbie Monad question
Henning Thielemann
lemming at henning-thielemann.de
Tue Jan 25 14:21:30 EST 2005
On Tue, 25 Jan 2005, [iso-8859-1] Simon Ulfsb=E4cker 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-examp=
le:
>
> readLn >>=3D \i -> readLn >>=3D \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 >>=3D (\i -> (readLn >>=3D (\j -> return (i + j))))
That is the first readLn is combined with the function
(\i -> (readLn >>=3D (\j -> return (i + j))))
which processes its input, in this case represented by the identifier i.
More information about the Haskell-Cafe
mailing list