Skip to content

Instantly share code, notes, and snippets.

@dtchepak
Last active August 29, 2015 14:01
Show Gist options
  • Save dtchepak/809cc7f1c9a9c665d8bd to your computer and use it in GitHub Desktop.
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)
-- 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