[Haskell-cafe] Enumerators, Enumeratees and Iterators

Sævar Berg s.b.saevarsson at gmail.com
Tue Jun 28 04:21:37 CEST 2011

Hey Café.

I've been playing with Enumerators, Iteratees and Enumeratees today after
having spent a few days writing a server application using lazy IO, then
reading slides from Oleg's DEFUN8 talk notes, and I quote: "Lazy IO in
serious, server-side programming is unprofessional", "I can talk a lot how
disturbingly, distressingly wrong lazy IO is theoretically, how it breaks
all equational reasoning" after which my OCD self has been eating me up to
take a proper look at this, so here I am.

I'm already beginning to see how Iteratees, Enumerators and Enumeratees can
be nifty, but I have a couple of questions about a couple of ideas and
whether, and if so how they can be implemented.

The first question is, I think, to be solved with enumeratees but I can't
really grok how.
Let's say I have an iteratee that consumes all input. Is it possible to
implement an enumeratee or something else to stick between the enumerator
and the iteratee to basically modify the input to the iteratee to only be a
part of the input?

Something like this:

enumFile "someFile" && printFileLines -- prints file with prepended line
enumFile "someFile" ?? onlyGet10Lines && printFileLines -- print only 10

The second question could actually have an application in the server I'm
writing. I was wondering if it was possible to write iteratees/enumerators
that would only generate/consume when a certain something was the next chunk
to be processed? It's a bit hard to explain, but let me try to give you an

Let's say my application takes input from the network which contains
commands that the server reacts to. Let's say I have a list of command
handlers that I want to run this command through, but the handlers will only
execute when they are passed the command that they are responsible for
Can this list of command handlers be enumerators/iteratees/enumeratees? E.g.
is it possible to 'concat' them, making them each peek at the next chunk to
see if it's theirs to handle and put it back if it isn't?

I know this is possible to do differently and I have an idea for how I would
do this, but I'm wondering if this is possible. If I can get answers to
either or both of the questions it would help me a bit on my way to
completely realize the roles that enumerators vs. iteratees vs. enumeratees
have, as the lines seem a bit blurred -- sometimes, anyway.

Thanks in advance. :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110628/3c3fc602/attachment.htm>

More information about the Haskell-Cafe mailing list