Re: [Haskell-cafe] Question about the Monad instance for Iteratee (from the enumerator package)

Daniel Schuessler wrote:
The thing I don't understand yet is the last line: Why is it OK to discard the leftover input from the (f x) Iteratee and yield just the leftover input from the first one (m0)?
First of all, the question is about an older version of Iteratee. For example, the following code http://okmij.org/ftp/Haskell/Iteratee/Iteratee.hs defines Iteratee a bit differently so the question does not apply.
data Iteratee a = IE_done a | IE_cont (Maybe ErrMsg) (Stream -> (Iteratee a,Stream))
instance Monad Iteratee where return = IE_done IE_done a >>= f = f a IE_cont e k >>= f = IE_cont e (docase . k) where docase (IE_done a, stream) = case f a of IE_cont Nothing k -> k stream i -> (i,stream) docase (i, s) = (i >>= f, s)
No left-over is discarded any more. Your question is about the previous design, called `The second design' described in Iteratee.hs. The corresponding comment block answers your question, please search for ``Justification for the case IE_done x s >>= f''. Please see http://okmij.org/ftp/Haskell/Iteratee/IterateeM.hs for the `production' case of Iteratee in a base monad. The file IterateeM.hs talks about one more design, and its drawbacks. It's all about finding the optimal trade-off, I guess.

This is a much cleaner definition of Iteratee and I'm happy to see it. When are you going to move from your FTP site to Github, by the way? :) Regards, John A. De Goes Twitter: @jdegoes LinkedIn: http://linkedin.com/in/jdegoes On Apr 21, 2011, at 12:32 AM, oleg@okmij.org wrote:
Daniel Schuessler wrote:
The thing I don't understand yet is the last line: Why is it OK to discard the leftover input from the (f x) Iteratee and yield just the leftover input from the first one (m0)?
First of all, the question is about an older version of Iteratee. For example, the following code http://okmij.org/ftp/Haskell/Iteratee/Iteratee.hs defines Iteratee a bit differently so the question does not apply.
data Iteratee a = IE_done a | IE_cont (Maybe ErrMsg) (Stream -> (Iteratee a,Stream))
instance Monad Iteratee where return = IE_done IE_done a >>= f = f a IE_cont e k >>= f = IE_cont e (docase . k) where docase (IE_done a, stream) = case f a of IE_cont Nothing k -> k stream i -> (i,stream) docase (i, s) = (i >>= f, s)
No left-over is discarded any more.
Your question is about the previous design, called `The second design' described in Iteratee.hs. The corresponding comment block answers your question, please search for ``Justification for the case IE_done x s >>= f''.
Please see http://okmij.org/ftp/Haskell/Iteratee/IterateeM.hs for the `production' case of Iteratee in a base monad. The file IterateeM.hs talks about one more design, and its drawbacks.
It's all about finding the optimal trade-off, I guess.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Thu, Apr 21, 2011 at 8:36 AM, John A. De Goes
This is a much cleaner definition of Iteratee and I'm happy to see it.
I'm confused by this comment. Isn't John Lato's implementation of Iteratee (on hackage) is based on the example implementation that Oleg pointed you towards?

John Lato's "iteratee" package is based on IterateeMCPS.hs[1]. I used IterateeM.hs for "enumerator", because when I benchmarked them the non-CPS version was something like 10% faster on most operations. The new IterateeM.hs solves some problems with the old encoding, but I haven't switched "enumerator" to it yet because it would break backwards compatibility. [1] http://okmij.org/ftp/Haskell/Iteratee/IterateeMCPS.hs

You wouldn't be so confused if you had actually looked at Lato's implementation and compared it to Oleg's most recent version. Regards, John A. De Goes Twitter: @jdegoes LinkedIn: http://linkedin.com/in/jdegoes On Apr 21, 2011, at 6:27 PM, Jason Dagit wrote:
On Thu, Apr 21, 2011 at 8:36 AM, John A. De Goes
wrote: This is a much cleaner definition of Iteratee and I'm happy to see it.
I'm confused by this comment. Isn't John Lato's implementation of Iteratee (on hackage) is based on the example implementation that Oleg pointed you towards?
participants (4)
-
Jason Dagit
-
John A. De Goes
-
John Millikin
-
oleg@okmij.org