0 | module Control.Monad.Continuation
2 | import public Control.Monad.Trans
3 | import public Control.Monad.Identity
6 | record ContT {0 ty : Type} (r : ty) (m : ty -> Type) (a : Type) where
8 | contT : (a -> m r) -> m r
11 | runCont : Applicative m => ContT () m () -> m ()
12 | runCont = ($
pure) . contT
15 | MonadTrans (ContT r) where
16 | lift m = MkContT (m >>=)
19 | Functor (ContT r m) where
20 | map f c = MkContT (c.contT . (. f))
23 | Applicative (ContT r m) where
24 | pure x = MkContT ($
x)
25 | (<*>) (MkContT f) (MkContT x) =
26 | MkContT $
\cb => f (x . (cb .))
29 | Monad (ContT r m) where
30 | join n = MkContT $
\cb => n.contT (($
cb) . contT)
33 | HasIO m => HasIO (ContT r m) where
34 | liftIO mio = MkContT (liftIO mio >>=)
37 | Cont : (r, a : Type) -> Type
38 | Cont r = ContT r Identity