Add a functor example

This commit is contained in:
Manuel Thalmann 2024-06-16 19:19:59 +02:00
parent 7772699814
commit e9a406a7b7

View 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
--