Created
October 28, 2018 13:52
-
-
Save lspitzner/378e0413505b1d6fa581e67720763d11 to your computer and use it in GitHub Desktop.
the ContCatchT monad
This file contains 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
newtype ContCatchT r e m a = | |
ContCatchT { getContCatchT :: ((e -> m r) -> a -> m r) -> (e -> m r) -> m r } | |
instance Functor (ContCatchT r e m) where | |
fmap f (ContCatchT k) = | |
ContCatchT $ \c1 c2 -> k (\c3 -> c1 c3 . f) c2 | |
instance Applicative (ContCatchT r e m) where | |
pure x = ContCatchT $ \c1 c2 -> c1 c2 x | |
ContCatchT cf <*> ContCatchT cx = ContCatchT | |
$ \c1 c2 -> cf (\c3f f -> cx (\c3x -> c1 c3x . f) c3f) c2 | |
instance Monad (ContCatchT r e m) where | |
return = pure | |
c >>= f = ContCatchT $ \c1 c2 -> | |
getContCatchT c (\c3x x -> getContCatchT (f x) c1 c3x) c2 | |
instance MonadIO m => MonadIO (ContCatchT r e m) where | |
liftIO m = ContCatchT $ \k1 k2 -> liftIO m >>= k1 k2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment