@@ -13,24 +13,25 @@ import Prelude
13
13
import Control.Monad.Cont.Class (class MonadCont , callCC )
14
14
import Control.Monad.Cont.Trans (class MonadTrans , ContT (..), lift , mapContT , runContT , withContT )
15
15
16
- import Data.Identity (Identity (..), runIdentity )
16
+ import Data.Identity (Identity (..))
17
+ import Data.Newtype (unwrap )
17
18
18
19
-- | The `Cont` monad is a synonym for the `ContT` monad transformer applied to
19
20
-- | the `Identity` monad.
20
21
type Cont r a = ContT r Identity a
21
22
22
23
-- | Creates a computation in the `Cont` monad.
23
24
cont :: forall a r . ((a -> r ) -> r ) -> Cont r a
24
- cont f = ContT (\c -> Identity (f (runIdentity <<< c)))
25
+ cont f = ContT (\c -> Identity (f (unwrap <<< c)))
25
26
26
27
-- | Runs a computation in the `Cont` monad.
27
28
runCont :: forall r a . ContT r Identity a -> (a -> r ) -> r
28
- runCont cc k = runIdentity (runContT cc (Identity <<< k))
29
+ runCont cc k = unwrap (runContT cc (Identity <<< k))
29
30
30
31
-- | Transform the result of a continuation-passing function.
31
32
mapCont :: forall r a . (r -> r ) -> Cont r a -> Cont r a
32
- mapCont f = mapContT (Identity <<< f <<< runIdentity )
33
+ mapCont f = mapContT (Identity <<< f <<< unwrap )
33
34
34
35
-- | Transform the continuation passed into the continuation-passing function.
35
36
withCont :: forall a b r . ((b -> r ) -> (a -> r )) -> Cont r a -> Cont r b
36
- withCont f = withContT (compose Identity <<< f <<< compose runIdentity )
37
+ withCont f = withContT (compose Identity <<< f <<< compose unwrap )
0 commit comments