@@ -26,3 +26,72 @@ instance monadWriterT :: (Monoid w, MonadCont m) => MonadCont (WriterT w m)
2626```
2727
2828
29+ ## Module Control.Monad.Cont.Trans
30+
31+ This module defines the CPS monad transformer.
32+
33+ #### ` ContT `
34+
35+ ``` purescript
36+ newtype ContT r m a
37+ = ContT ((a -> m r) -> m r)
38+ ```
39+
40+ The CPS monad transformer.
41+
42+ This monad transformer extends the base monad with the operation ` callCC ` .
43+
44+ ##### Instances
45+ ``` purescript
46+ instance functorContT :: (Monad m) => Functor (ContT r m)
47+ instance applyContT :: (Functor m, Monad m) => Apply (ContT r m)
48+ instance applicativeContT :: (Functor m, Monad m) => Applicative (ContT r m)
49+ instance bindContT :: (Monad m) => Bind (ContT r m)
50+ instance monadContT :: (Monad m) => Monad (ContT r m)
51+ instance monadTransContT :: MonadTrans (ContT r)
52+ instance monadEffContT :: (Monad m, MonadEff eff m) => MonadEff eff (ContT r m)
53+ ```
54+
55+ #### ` runContT `
56+
57+ ``` purescript
58+ runContT :: forall r m a. ContT r m a -> (a -> m r) -> m r
59+ ```
60+
61+ Run a computation in the ` ContT ` monad, by providing a continuation.
62+
63+ #### ` mapContT `
64+
65+ ``` purescript
66+ mapContT :: forall r m a. (m r -> m r) -> ContT r m a -> ContT r m a
67+ ```
68+
69+ Modify the underlying action in a ` ContT ` monad action.
70+
71+ #### ` withContT `
72+
73+ ``` purescript
74+ withContT :: forall r m a b. ((b -> m r) -> a -> m r) -> ContT r m a -> ContT r m b
75+ ```
76+
77+ Modify the continuation in a ` ContT ` monad action
78+
79+ #### ` callCC `
80+
81+ ``` purescript
82+ callCC :: forall r m a b. ((a -> ContT r m b) -> ContT r m a) -> ContT r m a
83+ ```
84+
85+ ` callCC ` , or _ call-with-current-continuation_ .
86+
87+ This action makes the current continuation available to the caller.
88+
89+ For example:
90+
91+ ``` purescript
92+ delay :: forall eff. Number -> ContT Unit (Eff (timeout :: Timeout | eff)) Unit
93+ delay n = callCC \cont ->
94+ lift $ setTimeout n (runContT (cont unit) (\_ -> return unit))
95+ ```
96+
97+
0 commit comments