[Haskell-cafe] Enumerators, Enumeratees and Iterators

Dmitry Olshansky olshanskydr at gmail.com
Tue Jun 28 08:03:05 CEST 2011


for the first question you can look at combinators in
for iteratee package or
enumerator package.

I doubt that I understand the second question. It seems that Map is more
natural here. You can transform list into enumerator for instance by
But I wonder what is the reason for that in your case?

2011/6/28 Sævar Berg <s.b.saevarsson at gmail.com>

> 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
> numbers
> enumFile "someFile" ?? onlyGet10Lines && printFileLines -- print only 10
> lines
> 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
> example.
> 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
> handling.
> 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. :)
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110628/293d7857/attachment.htm>

More information about the Haskell-Cafe mailing list