[Haskell-cafe] Question about the Monad instance for Iteratee (from the enumerator package)
John A. De Goes
john at n-brain.net
Thu Apr 21 00:12:34 CEST 2011
It's not OK and it's an artifact of the weak-typing and ill-defined semantics that pervade iteratee libraries. It's possible to do a lot of bad stuff, including binding with an iteratee yielding a remainder without consuming input.
Regards,
John A. De Goes
Twitter: @jdegoes
LinkedIn: http://linkedin.com/in/jdegoes
On Apr 19, 2011, at 6:27 AM, Daniel Schüssler wrote:
> Hello,
>
> for reference, said instance is:
>
>> instance Monad m => Monad (Iteratee a m) where
>> return x = yield x (Chunks [])
>>
>> m0 >>= f = ($ m0) $ fix $
>> \bind m -> Iteratee $ runIteratee m >>= \r1 ->
>> case r1 of
>> Continue k -> return (Continue (bind . k))
>> Error err -> return (Error err)
>> Yield x (Chunks []) -> runIteratee (f x)
>> Yield x extra -> runIteratee (f x) >>= \r2 ->
>> case r2 of
>> Continue k -> runIteratee (k extra)
>> Error err -> return (Error err)
>> Yield x' _ -> return (Yield x' extra)
>
> 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)?
>
> Cheers,
> Daniel
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
More information about the Haskell-Cafe
mailing list