The Applicative concept represents Functors with the ability to lift values and combine computations.
A Functor can only take a normal function and map it over a structure containing values to obtain a new structure containing values. Intuitively, an Applicative can also take a value and lift it into the structure. In addition, an Applicative can take a structure containing functions and apply it to a structure containing values to obtain a new structure containing values. By currying the function(s) inside the structure, it is then also possible to apply n-ary functions to n structures containing values.
lift and ap satisfying the laws below. An Applicative must also be a Functor.
Given an Applicative F, the following laws must be satisfied:
xs of tag F(A), xs of tag F(A) and functions-in-an-applicative \( fs : F(B \to C) \), \( gs : F(A \to B) \), x of tag A and functions \( f : A \to B \), x of tag A and functions-in-an-applicative \( fs : F(A \to B) \), apply(-, x) denotes the partial application of the apply function from the Functional module to the x argument.As a consequence of these laws, the model of Functor for F will satisfy the following for all objects xs of tag F(A) and functions \( f : A \to B \):
Functor (free model)Applicative F can be made a Functor by setting hana::lazy, hana::optional, hana::tuple
An applicative transformation is a function \( t : F(X) \to G(X) \) between two Applicatives F and G, where X can be any tag, and which preserves the operations of an Applicative. In other words, for all objects x of tag X, functions-in-an-applicative \( fs : F(X \to Y) \) and objects xs of tag F(X),
Functions | |
| times | boost::hana::A (T_1) \times \cdots \times A(T_n) \to A(U) @f$. const expr auto ap |
| Lifted application. More... | |
Variables | |
| template<typename A > | |
| constexpr auto | boost::hana::lift |
Lift a value into an Applicative structure. More... | |
| times boost::hana::A | ( | T_1 | ) | const |
#include <boost/hana/fwd/ap.hpp>
Lifted application.
Specifically, ap applies a structure containing functions to a structure containing values, and returns a new structure containing values. The exact way in which the functions are applied to the values depends on the Applicative.
ap can be called with two arguments or more; the functions in the f structure are curried and then applied to the values in each x... structure using the binary form of ap. Note that this requires the number of x... must match the arity of the functions in the f structure. In other words, ap(f, x1, ..., xN) is equivalent to
where x ap y is just ap(x, y) written in infix notation to emphasize the left associativity.
Given an Applicative A, the signature is
| f | A structure containing function(s). |
| x... | Structure(s) containing value(s) and on which f is applied. The number of structures must match the arity of the functions in the f structure. |
|
constexpr |
#include <boost/hana/fwd/lift.hpp>
Lift a value into an Applicative structure.
lift<A> takes a normal value and embeds it into a structure whose shape is represented by the A Applicative. Note that the value may be a function, in which case the created structure may be applied to another Applicative structure containing values.
Given an Applicative A, the signature is \( \mathtt{lift}_A : T \to A(T) \).
| A | A tag representing the Applicative into which the value is lifted. |
| x | The value to lift into the applicative. |