zhaw-fup/Exercises/exercise-5/Solution.hs

23 lines
392 B
Haskell
Raw Normal View History

2024-06-16 17:54:14 +00:00
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
--