[Haskell-cafe] Re: Left fold enumerator - a real pearl overlooked?

John Lato jwlato at gmail.com
Wed Mar 4 05:26:14 EST 2009


On Tue, Mar 3, 2009 at 1:03 AM, Henning Thielemann
<lemming at henning-thielemann.de> wrote:
>
> On Mon, 2 Mar 2009, John Lato wrote:
>
> While I think that the Iteratee pattern has benefits, I suspect that it
> can't be combined with regular lazy functions, e.g. of type [a] -> [a]. Say
> I have a chain of functions: read a file, parse it into a tag soup, parse
> that into an XML tree, transform that tree, format that into a string, write
> that to a file, and all of these functions are written in a lazy way, which
> is currently considered good style, I can't use them in conjunction with
> iteratees. This means, almost all Haskell libraries have to be rewritten or
> extended from lazy style to iteratee style. The question for me is then: Why
> having laziness in Haskell at all? Or at least, why having laziness by
> default, why not having laziness annotation instead of strictness
> annotation.
>

I'm not sure that this is a problem, at least not for all cases.  When
reading seekable streams, it is possible to have IO on demand provided
that all processing take place within the context of the Iteratee (see
Oleg's Tiff reader, http://okmij.org/ftp/Haskell/Iteratee/Tiff.hs, and
my wave reader,
http://inmachina.net/~jwlato/haskell/iteratee/src/Data/Iteratee/Codecs/Wave.hs).
 Also, since the inner monad can be any monad, not just IO, you should
be able to lift processing and computations into an iteratee in a
fairly straightforward manner.  File enumerators are only provided for
IO, but it's fairly easy to create versions for other monads as
necessary.  I've got one for StateT s IO, for example.

Now I do agree that this probably won't work in every case.  I would
suspect that parsers may have to be rewritten to use iteratees
(although I don't know to what extent because I don't work with
generic parsers).  I'm not sure in what other cases this would also be
true.  The best way to figure it out would be to have more people
using iteratees and reporting their findings.

Cheers,
John


More information about the Haskell-Cafe mailing list