Skip to content

Instantly share code, notes, and snippets.

@dminuoso
Last active December 8, 2017 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dminuoso/2b72dc344cf69ddef1bd41bdca7f2846 to your computer and use it in GitHub Desktop.
Save dminuoso/2b72dc344cf69ddef1bd41bdca7f2846 to your computer and use it in GitHub Desktop.
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