Created
February 16, 2011 21:52
-
-
Save gregorycollins/830313 to your computer and use it in GitHub Desktop.
new iteratee bind
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
instance Monad m => Monad (Iteratee a m) where | |
return x = yield x (Chunks []) | |
m >>= f = bind m f | |
{-# INLINE bind #-} | |
bind :: Monad m => | |
Iteratee a m b | |
-> (b -> Iteratee a m c) | |
-> Iteratee a m c | |
bind m0 f = bind' m0 | |
where | |
bind' m = m `seq` Iteratee $! runIteratee m >>= | |
\r1 -> case r1 of | |
Continue k -> k `seq` (return $! Continue $! \s -> bind' (k s)) | |
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
instance Monad m => Monad (Iteratee a m) where | |
return x = yield x (Chunks []) | |
m >>= f = Iteratee $ runIteratee m >>= | |
\r1 -> case r1 of | |
Continue k -> return (Continue ((>>= f) . 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment