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 /ch03_03-i.hs |
Diffstat (limited to 'ch03_03-i.hs')
-rw-r--r-- | ch03_03-i.hs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/ch03_03-i.hs b/ch03_03-i.hs new file mode 100644 index 0000000..ec12e08 --- /dev/null +++ b/ch03_03-i.hs @@ -0,0 +1,25 @@ +-- Exercise 3-i +-- Which of these types are `Functor`s? Give instances for the ones that are. + +-- `T1` is a `Functor`: +newtype T1 a + = T1 (Int -> a) + +instance Functor T1 where + fmap f (T1 g) = T1 $ f <$> g + +newtype T2 a + = T2 (a -> Int) + +newtype T3 a + = T3 (a -> a) + +newtype T4 a + = T4 ((Int -> a) -> Int) + +-- `T5` is a `Functor`: +newtype T5 a + = T5 ((a -> Int) -> Int) + +instance Functor T5 where + fmap f (T5 g) = T5 $ \f' -> g $ f' . f |