[Haskell-cafe] State monad in the wikibood article

TJ tjay.dreaming at gmail.com
Wed Feb 28 23:12:25 EST 2007


In the wikibook article here:
http://en.wikibooks.org/wiki/Haskell/Understanding_monads, which
really does an excellent job explaining things (nuclear waste
woohoo!), I am stuck at the following code snippet:

container >>= fn =
 \st -> let (a, st2)   = container st
            container2 = fn a
        in  container2 st2

What stumps me is that (>>=) is supposed to return a container, but if
we return (container2 st2) as in the code, then what we're really
returning is the contents of the container! So what would happen if we
do this:

nuclearWasteInContainer >>= processTheWaste >>= thoroughProcessTheWaste

It seems to me that the second (>>=) in the above expression would
have the arguments (nuclearWaste) and (nuclearWasteProcessor), when
what it really expects are (Container nuclearWaste) and
(nuclearWasteProcessor). So isn't something wrong with the definition
of (>>=) above? Or am I missing something?

(I know the article says that the type for their supposed State monad
at that point is not actually correct, and will be clarified further
on, but that seems to be irrelevant to my question.)


TJ the forever noobie.


More information about the Haskell-Cafe mailing list