TJ <[EMAIL PROTECTED]> said:
> 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!

Note the lambda abstraction (\st -> ...) at the beginning of the
definition. This means that (container >>= fn) returns a *function* that
maps an input state to the result of (container2 st2). It doesn't return
the result of (container st2) directly.

> 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.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to