19 lines
588 B
Haskell
19 lines
588 B
Haskell
-- Functor:
|
|
-- :t (replicate 3)
|
|
(replicate 3) :: a -> [a]
|
|
|
|
-- :t fmap (replicate 3)
|
|
(fmap (replicate 3)) :: f a -> f [a]
|
|
|
|
-- We say that (replicate 3) has been "lifted" to f
|
|
|
|
-- Also think of functors as things that output values.
|
|
-- fmap'ing a functor is attaching a modifier to the output(s) of the functor
|
|
-- partial applications of a function are themselves functors
|
|
-- fmap'ing these partial applications results in composition!
|
|
|
|
-- Applicative functors - Applicative class in Haskell
|
|
class (Functor f) => Applicative f where
|
|
pure :: a -> f a
|
|
(<*>) :: f (a -> b) -> (f a -> f b)
|