[Haskell-beginners] Re: Understanding Monadic I/O

Heinrich Apfelmus apfelmus at quantentunnel.de
Sun Jan 17 05:07:38 EST 2010

Markus Böhm wrote:
> Tx Heinrich. Could You explain how this "modelling the execution order
> as data dependency" works and how its tranlsated into sequential,
> imperative code? I mean in principle/for dummies.
> From my beginner's perspective I feel I need that insight to
> understand how sustainable the abstraction is.

I don't know the details, but I think it's translated like this:

    putStrLn "Hello" >> putStrLn "World"

  => { state monad }

    \w1 -> let (a,w2) = primPutStrLn "Hello" w1
           in primPutStrLn "World" w2

  => { print out C code }

    a = cprimPutStrLn("Hello");

The purpose of  w1  and  w2  is just to ensure that the first
cprimPutStrLn  is called before the second.

Not very enlightening overall, if you ask me. It's not necessary to
understand it anyway, the IO monad can be entirely understood as an
algebraic data type, see for instance

  Swierstra und Altenkirch. Beauty in the beast.

Heinrich Apfelmus


More information about the Beginners mailing list