[Haskell-cafe] Re: Fwd: Semantics of iteratees, enumerators, enumeratees?

Heinrich Apfelmus apfelmus at quantentunnel.de
Tue Aug 24 03:49:35 EDT 2010

Jason Dagit wrote:
> From a purely practical viewpoint I feel that treating the chunking
> as an abstraction leak might be missing the point.  If you said, you
> wanted the semantics to acknowledge the chunking but be invariant
> under the size or number of the chunks then I would be happier.
> I use iteratees when I need to be explicit about chunking and when I
> don't want the resources to "leak outside" of the stream processing.
> If you took those properties away, I wouldn't want to use it anymore
> because then it would just be an inelegant way to do things.

I'm curious, can you give an example where you want to be explicit about
chunking? I have a hard time imagining an example where chunking is
beneficial compared to getting each character in sequence. Chunking
seems to be common in C for reasons of performance, but how does that
apply to Haskell?

On the matter of leaking resources outside the stream processing,
Iteratee does not give you any guarantees, it's only a stylistic aid
(which can be powerful, of course). For instance, the following Iteratee
returns the whole stream as a list:

     getStream :: Iteratee e a m [a]
     getStream = Iteratee . return . Continue $ go []
         go xs EOF        = Yield xs EOF
         go xs (Chunk ys) = Continue $ go (xs++ys)

(using the API from  http://ianen.org/articles/understanding-iteratees/ )

Heinrich Apfelmus


More information about the Haskell-Cafe mailing list