Last active
December 8, 2017 18:14
-
-
Save dminuoso/2b72dc344cf69ddef1bd41bdca7f2846 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ContT where | |
import Control.Monad.Trans.Class | |
newtype ContT r m a = ContT { runContT :: (a -> m r) -> m r } | |
instance Functor (ContT r m) where | |
fmap f (ContT cv) = ContT $ \c -> | |
cv (c . f) | |
instance Applicative (ContT r m) where | |
pure a = ContT $ \c -> c a | |
(ContT cf) <*> (ContT cv) = ContT $ \c -> | |
cf $ \f -> | |
cv (c . f) | |
instance Monad (ContT r m) where | |
return = pure | |
(ContT ca) >>= acb = ContT $ \c -> | |
ca $ \a' -> | |
runContT (acb a') c | |
instance MonadTrans (ContT r) where | |
lift m = ContT (\k -> m >>= k) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment