> From: David Leimbach <[email protected]>
> I'm looking at iteratee as a way to replace my erroneous and really
> inefficient lazy-IO-based backend for an expect like Monad DSL I've been
> working for about 6 months or so now on and off.
> The problem is I want something like:
> expect "some String"
> send "some response"
> to block or perhaps timeout, depending on the environment, looking for "some
> String" on an input Handle, and it appears that iteratee works in a very
> fixed block size. While a fixed block size is ok, if I can put back unused
> bytes into the enumerator somehow (I may need to put a LOT back in some
> cases, but in the common case I will not need to put any back as most
> expect-like scripts typically catch the last few bytes of data sent before
> the peer is blocked waiting for a response...)
I'm quite sure I don't know what you're trying to do. The only time I
can think of needing this is if you're running an iteratee on a file
handle, keeping the handle open, then running another iteratee on it.
Is this what you're doing? If so, I would make a new run function:
runResidue :: (Monad m, SC.StreamChunk s el) => IterateeG s el m a -> m (a, s)
runResidue iter = runIter iter (EOF Nothing) >>= \res ->
case res of
Done x s -> return (x, s)
Cont _ e -> error $ "control message: " ++ show e
This function will return the unused portion of the stream, then you
can do this:
enumResidue :: Handle -> s -> EnumeratorGM s el m a
enumResidue h s = enumPure1Chunk s >. enumHandle h
Is this what you need? If I'm completely wrong about what you're
trying to do (or you're using multiple threads), there are other
You also may want to look at iteratee-HEAD. The implementation has
been cleaned up a lot, the block sizes are user-specified, and there's
an exception-based, user-extensible mechanism for iteratees to alter
Haskell-Cafe mailing list