[Haskell-cafe] safe lazy IO or Iteratee?

Nicolas Pouillard nicolas.pouillard at gmail.com
Fri Feb 5 04:02:44 EST 2010


On Thu, 4 Feb 2010 12:51:59 -0800, John Millikin <jmillikin at gmail.com> wrote:
> Both have advantages and disadvantages. The primary advantage of lazy
> IO over iteratees is that it's much, *much* easier to understand --
> existing experience with monads can be used immediately. The downsides
> of lazy IO, of course, are well documented[1][2][3].
> 
> Some are fixed by the safe/strict IO packages. However, safe lazy IO
> is still "unpredictable" in that it's difficult to know how many
> resources will be used, the order of some operations (eg, releasing
> handles), or whether some particular expression will throw an
> exception.

I don't know if you include safe-lazy-io [1] here but its purpose is to cure
these downsides. In particular file handles are properly released on time
even when asking for a stream of a list of files. Moreover exceptions are
not hidden and can be caught properly in the wrapping IO layer.

Some restrictions are there though. For instance one cannot arbitrarily
interleave different streams, one have to use one of the predefined
interleaving scheme. Another limitation is that the client cannot react
to errors without getting back to the non-lazy IO world, however this
is a big selling point as well of lazy-IO: "reuse pure code".

I don't want to claim that (safe-)lazy-IO should be used in all situations,
this would be terribly wrong. However I recommend it for situations were
the interleaving of input is standard and errors have not to be caught
in the processing code.

Best regards,

[1]: http://www.haskell.org/pipermail/haskell/2009-March/021133.html

-- 
Nicolas Pouillard
http://nicolaspouillard.fr


More information about the Haskell-Cafe mailing list