@@ -13,24 +13,25 @@ import Prelude
1313import Control.Monad.Cont.Class (class MonadCont , callCC )
1414import Control.Monad.Cont.Trans (class MonadTrans , ContT (..), lift , mapContT , runContT , withContT )
1515
16- import Data.Identity (Identity (..), runIdentity )
16+ import Data.Identity (Identity (..))
17+ import Data.Newtype (unwrap )
1718
1819-- | The `Cont` monad is a synonym for the `ContT` monad transformer applied to
1920-- | the `Identity` monad.
2021type Cont r a = ContT r Identity a
2122
2223-- | Creates a computation in the `Cont` monad.
2324cont :: 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)))
2526
2627-- | Runs a computation in the `Cont` monad.
2728runCont :: 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))
2930
3031-- | Transform the result of a continuation-passing function.
3132mapCont :: 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 )
3334
3435-- | Transform the continuation passed into the continuation-passing function.
3536withCont :: 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