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

Markus Böhm markus.boehm at googlemail.com
Thu Jan 14 06:43:47 EST 2010

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.

P.S.: Looking at forum discussions about simple, standard examples
like Fibonacci, arithmetic mean etc. I get the impression that the
naive, beautiful solution is evtl. not scalable (performance, memory)
and that it's necessary to understand the runtime behaviour underneath
the abstraction. Would You confirm that impression?

-- Markus

On Thu, Jan 14, 2010 at 10:36 AM, Heinrich Apfelmus
<apfelmus at quantentunnel.de> wrote:
> Markus Böhm wrote:
>> Hi, I'd like to understand in principle, how monadic I/O actions and
>> combinators (>>=) are translated into imperative C--, to be executed
>> sequentially.
>> Does sequencing of IO actions mean nesting of C-- functions and
>> passing values/state via additional function parameters?
>> Is there any material with examples available?
>> P.S.: Just to understand the magic better. I need it.
> Well, the key point of the IO monad is of course that the internals are
> abstracted away. I'm not sure you will get much understanding out of them.
> If I am informed correctly, GHC represents IO as
>   newtype IO a = IO ( World -> (# a, World #) )
> But  World  is just a dummy type, it models the execution order as data
> dependencies so that the optimizer doesn't mess with it. In other word,
>  World  is stripped out completely, primitives like  putChar  are pretty
> much just compiled down to foreign function calls in C--.
> There are other possibilities, I believe NHC and YHC represent IO as
>   newtype IO a = IO ( World -> a )
> Again, the  World  argument is just a dummy.
> Regards,
> Heinrich Apfelmus
> --
> http://apfelmus.nfshost.com
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners

More information about the Beginners mailing list