Paraphrasing this answer: Applicative functors are functors for which there is also a natural transformation that preserve monoidal structure of their source/target categories. In the case of Haskell's Applicative
endofunctors (because their source and target categories is Hask), the monoidal structure is the Cartesian product. So for an Applicative
functor there are natural transformations φ: (f a, f b) -> f (a, b)
and ι: () -> f ()
. So we could define Applicative
as
class Functor f => Applicative' f where
φ :: (f a, f b) -> f (a, b)
ι :: f () -- it could be \() -> f (),
-- but \() -> ... is redundant
This definition is equivalent to the standard one. We can express
φ = uncurry (liftA2 (,))
= \(x, y) -> (,) <$> x <*> y
ι = pure ()
and conversely
pure x = fmap (\() -> x) ι
f <*> x = fmap (uncurry ($)) (φ (f, x))
So pure
and <*>
is an alternative way how to define this natural transformation.