From 6a0d7f5c434c3564d0119befb6799fd77581050a Mon Sep 17 00:00:00 2001 From: Paul Oliver Date: Fri, 3 Jan 2025 11:01:20 -0800 Subject: Initial --- ch03_03-i.hs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 ch03_03-i.hs (limited to 'ch03_03-i.hs') 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 -- cgit v1.2.1