5 | data Cont : (r : Type) -> (a : Type) -> Type where
6 | ContOf : ((a -> r) -> r) -> Cont r a
9 | Functor (Cont r) where
10 | map f (ContOf a_cps) = ContOf (\k => a_cps (k . f))
13 | Applicative (Cont r) where
14 | pure x = ContOf (\f => f x)
15 | (ContOf f) <*> (ContOf v) = ContOf (\c => f (\g => v (c . g)))
18 | Monad (Cont r) where
19 | (ContOf a_cps) >>= arrb = ContOf (\k => a_cps (\a => let ContOf unCont = arrb a in unCont k))
22 | data DIterator : (i : Type)
29 | Result : r -> DIterator i o i2 o2 r
30 | Susp : o -> ( i -> DIterator i o i2 o2 r) -> DIterator i o i2 o2 r
31 | Susp2 : o2 -> ( i2 -> DIterator i o i2 o2 r) -> DIterator i o i2 o2 r
34 | Iterator: Type -> Type -> Type -> Type
35 | Iterator i o r = DIterator i o Void Void r
38 | toIterator : Cont (DIterator i o i2 o2 r) r -> DIterator i o i2 o2 r
39 | toIterator (ContOf unCont) = unCont Result
42 | yieldGet : o -> Cont (DIterator i o i2 o2 r) i
43 | yieldGet = ContOf . Susp
46 | yieldGet2 : o2 -> Cont (DIterator i o i2 o2 r) i2
47 | yieldGet2 = ContOf . Susp2