[Haskell-cafe] understanding enumerator/iteratee

Artyom Shalkhakov artyom.shalkhakov at gmail.com
Mon Dec 22 06:17:33 EST 2008


Hi Jason!

2008/12/22 Jason Dusek <jason.dusek at gmail.com>:
>  So an iteratee is not like a cursor because it does not "own"
>  the collection -- it just tells us how to step it. The
>  enumerator "owns" the collection and provides a way to scope
>  resource use?

Iteratee does not know anything about resources,
it doesn't need to. It is just a function which, given an input
stream (which is either EOF, block of data or an IO error string),
decides what to do, one of:
* yield with some (useful) results (and with the rest of the input)
* request more input by returning a continuation

The enumerator on the other hand, decides when to open the
resource (a file, for example), when to close it, and how to "step"
through it. Iteratee only gets the fruits of this hard work. :)

> it just tells us how to step it

I would say that it just tells us how to react to various forms of
input. :) This is much like the function you pass to foldr.

I hope this clarifies iteratees a bit (and that my understanding
is correct).

Cheers,
Artyom Shalkhakov.


More information about the Haskell-Cafe mailing list