Re: [Haskell-cafe] Fwd: Semantics of iteratees, enumerators, enumeratees?

From: Stephen Tetley
On 24 August 2010 13:00, John Lato
wrote: This is how I think of them. I particularly your description of them as a foldl with a "pause" button. Maybe it would be helpful to consider iteratees along with delimited continuations?
Aren't they closer - in implementation and by supported operations - to resumptions monads?
See many papers by William Harrison here: http://www.cs.missouri.edu/~harrisonwl/abstracts.html
I'm not familiar with resumption monads. I'll have to read some of the papers and get back to you. John

On Tue, Aug 24, 2010 at 11:44 AM, John Lato
Aren't they closer - in implementation and by supported operations - to resumptions monads?
See many papers by William Harrison here: http://www.cs.missouri.edu/~harrisonwl/abstracts.html
I'm not familiar with resumption monads. I'll have to read some of the papers and get back to you.
From glancing at the papers myself, the concept seems quite simple. The "cheap threads" paper defines a minimal resumption monad as:
From which we can obtain an automaton with a halt state using the reader monad, or an (Iteratee m) using (ReaderT chunk m). But this is in fact somewhat misleading, because ResT is not actually a monad
data Res a = Done a | Pause (Res a) ...which is just a single value nested in a bunch of superfluous constructors. It then parameterizes this by an arbitrary monad to create a resumption "monad transformer": data ResT m a = Done a | Pause (m (ResT m a)) transformer except in a trivial sense! (>>=) is defined for (ResT m) as: (Done v) >>= f = f v (Pause r) >>= f = Pause (r >>= \k -> return (k >>= f)) Which is equivalent to: (Done v) >>= f = f v (Pause r) >>= f = Pause (fmap (>>= f) r) In other words, ResT constructs a Monad from any Functor, not just another Monad. If memory serves me, this is actually nothing more than the free monad of the functor. In fact, this makes a lot more sense than my earlier reduction in terms of an Automaton arrow: Given a chunk type "c" and some Functor "f", the functor composition of ((->) c) and f gives another functor, the free monad of which is roughly an Iteratee for "c" and "f", modulo some details regarding error handling and returning unused input that I don't think change the essential structure significantly. The obvious question of what the dual of a resumption monad (and, by extension, an Iteratee) looks like is simple enough. The minimal resumption monad is the free monad of Identity; the cofree comonad of Identity is an infinite stream of values. An Iteratee is an automaton built from functor composition with Reader; the cofree comonad of the same also gives an automaton, but one with no halting state that produces an output immediately at each step based on the current state, akin to a Moore-style machine instead of the Mealy-style Automaton arrow. Being a source of data, either form of "co-resumption comonad" would probably make a serviceable Enumerator type, given some recursive driver function that pulls data from the stream and stuffs it into the Iteratee. All of which leads me to suspect that any implementation of Iteratees could probably be replaced by category-extras and about eleven lines of zygohistomorphic prepromorphisms or whatever. - C.

Thanks for taking a look - I've never got round to investigating the connection properly but have noticed the strong similarity between the data type defintions of the ResT and Iteratee. William Harrison makes the interesting point in the "Cheap Threads" papers that by itself the resumption monad is really quite "dull" - adding state (which would be "chunked" input for an iteratee) makes it much more useful.
participants (3)
-
C. McCann
-
John Lato
-
Stephen Tetley