Solve Functor task 1
This commit is contained in:
parent
e9a406a7b7
commit
1708105d9f
1 changed files with 22 additions and 0 deletions
22
Exercises/exercise-5/Solution.hs
Normal file
22
Exercises/exercise-5/Solution.hs
Normal 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
|
||||||
|
--
|
Loading…
Reference in a new issue