blob: 205606a8a46b48f5612e226f328b00fa99dcea82 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
-- Exercise 6.4-iv
-- There is also a monad transformer version of `Cont`. Implement it.
newtype ContT t a = ContT
{ unContT :: forall r. (a -> t r) -> t r
}
instance Functor (ContT t) where
fmap f (ContT a) = ContT $ \c -> a $ c . f
instance Applicative (ContT t) where
pure a = ContT $ \c -> c a
ContT f <*> ContT a = ContT $ \c -> f $ \c' -> a $ c . c'
instance Monad (ContT t) where
ContT a >>= f = ContT $ \c -> a $ \c' -> unContT (f c') c
|