[Haskell-cafe] Iteratee rest and monad instance

Tilo Wiklund noteventime at gmail.com
Sat Jun 12 07:12:45 EDT 2010


I've mostly been studying the Iteratee IO slides (with notes), so
these things may already have been noted elsewhere (though I have not
been able to find them with my cursory search). Also excuse my
probably somewhat confused terminology, I hope I get the point across
anyway.

In both the slides and the current hackage package "finished"
iteratees carry with them (in the constructor) the rest of the stream.
I may miss something obvious here, but this seems to lead to some
fishy details in the monad instance of iteratees presented in the
slides.

Firstly the iteratee given by return/pure has to carry with it a rest
before a stream comes into the picture, though I guess one could argue
that (Chunk "") is some kind of identity but this does not seem to be
enforced in any way.

Furthermore in the bind operator the rest of the iteratee from the
bound (RHS) function seems to be ignored at some times and not at
others (depending on the rest of the bound LHS value).

I am probably missing something obvious or something relating to
optimisation/server software but defining iteratees as "Iteratee s a =
Cont (s -> Either (s, a) (Iteratee s a))" seems to lead to a more
natural monad instance, and does not suffer from (what seems to me to
be an issue) having to make predictions about the stream it will be
passed.

My question is thus, why the "rest" stream has to be carried by an
Iteratee constructor, rather then be part of the value of the
continuation function.


More information about the Haskell-Cafe mailing list