iteratee [] suggestion for mapStreamM

John Lato jwlato at gmail.com
Mon Aug 16 11:10:51 EDT 2010


On Sun, Aug 15, 2010 at 1:20 AM, Ben <midfield at gmail.com> wrote:

> A suggestion for Data.Iteratee.ListLike :
>
> mapStreamM :: (Monad m) =>
>  (el -> m el')
>  -> Enumeratee [el] [el'] m a
> mapStreamM mf = eneeCheckIfDone (liftI . step)
>  where
>    step k (Chunk xs)
>      | LL.null xs = liftI (step k)
>      | otherwise  = joinIM $ do ys <- mapM mf xs
>                                 return $ mapStreamM mf $ k (Chunk ys)
>    step k s       = idone (liftI k) s
>
> an improvement would be something that actually uses the ListLike
> class (or some monadic extension of it.)
>

Thanks for this suggestion; I think it would be useful.

This gets to a related issue I've been struggling with for some time.  I
would like for iteratee to support using mutable buffers.  I believe this
could be very efficient as it would completely bypass a large amount of
allocation/gc work.  There are two primary issues I have so far:

1)  I don't know how to make them 100% compatible with standard iteratees
because the Monad instance needs to be slightly different.  In my test
implementation I use a newtype of Iteratee, which is mostly satisfactory.

2) Everything in ListLike needs to be re-written for a monadic version.
 ListLike itself is not widely used, but for mutable buffers there's even
more disparity.  At least ListLike instances for Vector, Text, etc. can be
written relatively mechanically.

Is there any interest in further developments in this direction?

John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.haskell.org/pipermail/iteratee/attachments/20100816/f787aa43/attachment.htm 


More information about the Iteratee mailing list