Solve Functor task 1

This commit is contained in:
Manuel Thalmann 2024-06-16 19:54:14 +02:00
parent e9a406a7b7
commit 1708105d9f

View file

@ -0,0 +1,22 @@
newtype Boxed a = Boxed {unbox :: a}
instance Functor Boxed where
fmap f (Boxed a) = Boxed (f a)
test1 = unbox (fmap id b) == unbox b
where
b = Boxed { unbox = 1 :: Integer }
-- >>> test1
-- True
--
test2 = unbox (fmap (f . g) b) == unbox (fmap f $ fmap g b)
where
b = Boxed { unbox = 1 :: Integer }
f = (+9)
g = (*11)
-- >>> test2
-- True
--