Common instances of Applicative Maybe Maybe is an applicative functor containing a possibly-absent value. pure lifts the given value into Maybe by applying Just to it. The (<*>) function applies a function wrapped in a Maybe to a value in a Maybe. If both the function and the value are present (constructed with Just), the function is applied to the value and the wrapped result is returned. If either is missing, the computation can't proceed and Nothing is returned instead. Lists One way for lists to fit the type signature <*> :: [a -> b] -> [a] -> [b] is to take the two lists' Cartesian product, pairing up each element of the first list with each element of the second one: This is usually interpreted as emulating nondeterminism, with a list of values standing for a nondeterministic value whose possible values range over that list; so a combination of two nondeterministic values ranges over all possible combinations of the values in the two lists: Infinite streams and zip-lists There's a class of Applicatives which "zip" their two inputs together. One simple example is that of infinite streams: Stream's Applicative instance applies a stream of functions to a stream of arguments point-wise, pairing up the values in the two streams by position. pure returns a constant stream – an infinite list of a single fixed value: Lists too admit a "zippy" Applicative instance, for which there exists the ZipList newtype: Since zip trims its result according to the shortest input, the only implementation of pure that satisfies the Applicative laws is one which returns an infinite list: For example: The two possibilities remind us of the outer and the inner product, similar to multiplying a 1-column (n x 1) matrix with a 1-row (1 x m) one in the first case, getting the n x m matrix as a result (but flattened); or multiplying a 1-row and a 1-column matrices (but without the summing up) in the second case. Functions When specialised to functions (->) r, the type signatures of pure and <*> match those of the K and S combinators, respectively: pure must be const, and <*> takes a pair of functions and applies them each to a fixed argument, applying the two results: Functions are the prototypical "zippy" applicative. For example, since infinite streams are isomorphic to (->) Nat, ... ... representing streams in a higher-order way produces the zippy Applicative instance automatically. Definition Note the Functor constraint on f. The pure function returns its argument embedded in the Applicative structure. The infix function <*> (pronounced "apply") is very similar to fmap except with the function embedded in the Applicative structure. A correct instance of Applicative should satisfy the applicative laws, though these are not enforced by the compiler: |