[Haskell-cafe] Lazier I/O?

Wolfgang Jeltsch wolfgang at jeltsch.net
Mon Nov 28 15:00:15 EST 2005


Am Montag, 28. November 2005 13:27 schrieb Dimitry Golubovsky:
> [...]

> What is desired is to have the IO actions perform as their results are
> needed. I am assuming some knowledge that those actions have only
> limited scope of side effects (e. g. order of outputs within a window is
> significant, but order of appearance of those windows on the screen may
> not be). I see some way to do this by writing regular non-monadic
> Haskell stuff, representing each side effects scope (i. e. where
> ordering of actions is necessary) with its own instance of an I/O like
> monad (but runnable from an outside non-monadic code), and then using
> unsafePerformIO as needed. But there may be some framework already
> developed (albeit with unsafePerformIO, but hiding it from application
> developers).

Be very careful with unsafePerformIO.  When using it, compiler optimizations 
are likely to change the semantics of your program.  In my diploma thesis, I 
developed a framework for "lazy execution", based on two special monads.  
First, I implemented these monads on top of unsafePerformIO.  Then I had to 
discover that it was practically impossible to make this safe but that it was 
possible to implement these monads on top of unsafeInterleaveIO which I did 
then.

> Any ideas, pointers?

You might want to have a look at my thesis.  Alas, it's written in German but 
maybe the Haskell code it contains is useful for you.  It can be downloaded 
via http://www.informatik.tu-cottbus.de/~jeltsch/diplomarbeit/.  Chapter 4 is 
the "lazy execution" part.

> Thanks
>
> Dimitry

Best wishes,
Wolfgang


More information about the Haskell-Cafe mailing list