diff options
author | Paul Oliver <contact@pauloliver.dev> | 2025-01-03 11:01:20 -0800 |
---|---|---|
committer | Paul Oliver <contact@pauloliver.dev> | 2025-01-05 09:59:10 -0800 |
commit | 6a0d7f5c434c3564d0119befb6799fd77581050a (patch) | |
tree | f20bc998290211d2a895523417ad32e297b31af0 /ch06_06.4-iv.hs |
Diffstat (limited to 'ch06_06.4-iv.hs')
-rw-r--r-- | ch06_06.4-iv.hs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/ch06_06.4-iv.hs b/ch06_06.4-iv.hs new file mode 100644 index 0000000..205606a --- /dev/null +++ b/ch06_06.4-iv.hs @@ -0,0 +1,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 |