In Haskell, Applicative functors are functors such that two functorial values can be combined into one, whilst the two values inside are combined via a functional application. An applicative functor has more structure than a functor but less than a monad.
In Haskell, applicative functors are functors such that two functorial values (of type Applicative f => f a
) can be combined into one, and the two values inside will be combined via a functional application (so the types "on the inside" must be compatible).
Definition
class (Functor f) => Applicative f where
pure :: a -> f a -- injection
(<*>) :: f (a -> b) -> f a -> f b -- combination
The pure
function lifts any value into the functor. (<*>)
changes a functorial function into a function over functorial values. Applicative functor should satisfy some laws:
pure id <*> v = v -- Identity
pure (.) <*> u <*> v <*> w = u <*> (v <*> w) -- Composition
pure f <*> pure x = pure (f x) -- Homomorphism
u <*> pure y = pure ($ y) <*> u -- Interchange
And the Functor instance should satisfy the following law:
fmap f x = pure f <*> x -- Fmap