23 lines
392 B
Haskell
23 lines
392 B
Haskell
|
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
|
||
|
--
|