Last active
August 29, 2015 14:01
-
-
Save dtchepak/809cc7f1c9a9c665d8bd to your computer and use it in GitHub Desktop.
Iteratee example from slide 12 of "A Parsing Trifecta" (http://comonad.com/reader/wp-content/uploads/2009/08/A-Parsing-Trifecta.pdf)
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
-- http://comonad.com/reader/wp-content/uploads/2009/08/A-Parsing-Trifecta.pdf | |
-- | |
import Prelude hiding (null) | |
import Data.ByteString | |
data Input = Chunk ByteString | EOF | |
data Iteratee a | |
= Return a Input | |
| Cont (Input -> Iteratee a) | |
instance Monad Iteratee where | |
return a = Return a (Chunk empty) | |
Return a (Chunk e) >>= f | null e = k -- ?? | |
Return a i >>= f = case f a of | |
Return b _ -> Return b i | |
Cont k -> k i | |
Cont k >>= f = Cont (k >=> f) | |
where (>=>) a b x = a x >>= b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment