[Haskell-cafe] Monad Description For Imperative Programmer

Andrew Wagner wagner.andrew at gmail.com
Wed Aug 1 09:27:43 EDT 2007

> say you have this code :
>    putStrLn "1" >> putStrLn "2" >> putStrLn "3"
> you can imagine each of the calls to putStrLn gets implicitly passed a
> variable (here, the world ) and they happen in succession so it's
> "like a loop".

It breaks down further as soon as you add any amount of complexity to
the code as well. E.g.:

putStrLn "1" >> getLine >>= \line -> putStrLn line >> putStrLn "end"

This prints something, gets something from the user and prints it, and
then prints something else. The equivalent imperative pseudo-code is
something like:
print "foo";
line = inputLine();
print line;
print "end";

Not loop-ish at all!

More information about the Haskell-Cafe mailing list