Hoodlums Message Board › Iteratees and Enumerators
At the end of this month's session, I felt a little unsatisfied, but as I reflected on it the next day, I realized I had actually learned quite a lot. I thought I'd post my new, very high-level, summary of Iteratees and Enumarators. This is focused on the Enumerators package, but I think most of it applies to the others as well.
- Treat Iteratees, Enumerators and Enumeratees as black boxes - don't worry about how they are implemented, don't even worry about the types behind the definitions.
- An Iteratee a m b consumes a stream, of a's and ultimately results in a b in the monad m - don't picture them as arrows from a's to b's, the b is a final result and you don't chain the output from one Iteratee to the input of another. Iteratees are the end of the chain.
- An Enumerator a m b is a producer of a stream of a's that, when given an Iteratee a m b, will result in a b in the monad m - These produce a's, not b's. The b is always a type variable until it is bound to an Iteratee. The type behind the synonym is just confusing - I understand it now, but it doesn't help you understand how to use the package.
- An Enumeratee a1 a2 m b is a stream converter that can be placed between an Enumarator a1 m b and a an Iteratee a2 m b - again, the type behind the synonym does more to confuse than to explain.
- Use := to add some processing to the stream from an Enumerator - this takes an Enumerator and an Enumeratee and gives a new Enumerator.
- Use =: to add some processing to the stream into an Iteratee - this takes an Enumeratee and an Iteratee and gives a new Iteratee.
- Use $$ to pipe the stream from an Enumerator into an Iteratee - oddly this give a new Iteratee, but this Iteratee doesn't expect any input, the bound in Enumerator provides the input to the Iteratee. I believe this is more intuitive in the IterIO package.
- The library provides all the Enumerators, Enumeratees and Iteratees you'll need, you just need to plug them together, not build your own.
- You can use monadic or applicative composition to compose Iteratees sequentially - the Iteratees each consume part of the same input stream, just like parsers.
I've tidied the code we wrote at http://tinyurl.com/ho.... You can scroll back in time to see the history.
What I have said here is probably an over simplification and parts of it may be not entirely true, but it should give you enough to get going.