In computer science, applicative functors (also known as idioms) are the programming equivalent of lax monoidal functors with a tensorial strength in category theory.
A strong monad gives rise to an applicative functor, but not all applicative functors result from monads. Unlike monads, applicative functors are closed under composition.
An applicative functorΒ in a closed (symmetric) monoidal category is given by natural transformations and , satisfying unit and associativity coherence.
class (Functor f) => Applicative f where
pure :: a -> f a
(<*>) :: f (a -> b) -> f a -> f b
It defines a strong lax monoidal endofunctor as follows:
Conversely, given such an endofunctor , one can consider the following applicative:
There are two ways to define List as an applicative functor within the category of data types. In Haskell, the first is the default implementation, while the second is accessible via the ZipList newtype. They can be presented as an instance of the Applicative type class, or, equivalently, as an instance of the Monoidal type class.
instance Applicative List where
pure x = [x]
fs <*> xs = [ f x | f <- fs, x <- xs ]
instance Monoidal List where
unit = [()]
as β bs = [ (a, b) | a <- as, b <- bs ]
and
instance Applicative List where
pure x = repeat x
fs <*> xs = zipWith (\f x -> f x) fs xs
instance Monoidal List where
unit = repeat ()
as β bs = zip as bs
with the canonical strength being defined as follows:
strength :: Functor f => (a, f b) -> f (a, b)
strength (a, fb) = fmap (a,) fb
Conor McBride, Ross Paterson: Applicative programming with effects, Journal of Functional Programming 18 01 (2008) 1-13 [doi:10.1017/S0956796807006326; authorβs version]
Ross Paterson: Constructing Applicative Functors, in: Mathematics of Program Construction, Madrid, 2012, Lecture Notes in Computer Science 7342, Springer, (2012) 300-323 [doi:10.1007/978-3-642-31113-0_15, webpage]
Review:
Last revised on November 4, 2025 at 04:46:29. See the history of this page for a list of all contributions to it.