Add a functor example
This commit is contained in:
parent
7772699814
commit
e9a406a7b7
10
Exercises/exercise-5/FunctorExample.hs
Normal file
10
Exercises/exercise-5/FunctorExample.hs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
-- Generic type
|
||||||
|
newtype Data a = Data {value :: a}
|
||||||
|
|
||||||
|
-- Implement generic type conversion of `Data`
|
||||||
|
instance Functor Data where
|
||||||
|
fmap f (Data val) = Data (f val)
|
||||||
|
|
||||||
|
-- >>> value ((*9) <$> (Data { value = 2 }))
|
||||||
|
-- 18
|
||||||
|
--
|
Loading…
Reference in a new issue