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

Heinrich Apfelmus apfelmus at quantentunnel.de
Mon Aug 23 08:38:29 EDT 2010


Luke Palmer wrote:
> Heinrich Apfelmus wrote:
>> Conal Elliott wrote:
>>> For anyone interested in iteratees (etc) and not yet on the iteratees
>>> mailing list.
>>>
>>> I'm asking about what iteratees *mean* (denote), independent of the
>>> various implementations.
>>
>> In my world view, iteratees are just a monad M with a single operation
>>
>>    symbol :: M Char
>>
>> that reads the next symbol from an input stream.
> 
> So perhaps this could be a reasonable semantics?
> 
> Iteratee a = [Char] -> Maybe (a, [Char])
>            = MaybeT (State [Char]) a
> 
> symbol [] = Nothing
> symbol (c:cs) = Just (c, cs)
> 
> I'm not experienced with iteratees. Does this miss something?

 From a purely denotational point of view, that's a reasonable semantics.

However, and that's the main point, with this particular semantics, it 
is impossible to implement

     runHandle :: M a -> Handle -> IO a

without using  unsafeInterleaveIO . Typical implementations of iteratees 
do make that possible, by being able to suspend the iteratee after 
feeding it a character.


There are also enumerators and enumeratees. I think that

     purpose of enumerator =
	run an iteratee on multiple sources
         (i.e. first part of the input from a  Handle ,
           second part from a  String )

     purpose of enumeratee =
         iteratee as a stream transformer, i.e. as a map [x] -> [y]

I am not sure whether this elaborate reinvention of the standard lists 
functions is worth the trouble.


Regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com



More information about the Haskell-Cafe mailing list