Applicative -is:module

A functor with application, providing operations to
  • embed pure expressions (pure), and
  • sequence computations and combine their results (<*> and liftA2).
A minimal complete definition must include implementations of pure and of either <*> or liftA2. If it defines both, then they must behave the same as their default definitions:
(<*>) = liftA2 id
liftA2 f x y = f <$> x <*> y
Further, any definition must satisfy the following: The other methods have the following default definitions, which may be overridden with equivalent specialized implementations: As a consequence of these laws, the Functor instance for f will satisfy It may be useful to note that supposing
forall x y. p (q x y) = f x . g y
it follows from the above that
liftA2 p (liftA2 q u v) = liftA2 f u . liftA2 g v
If f is also a Monad, it should satisfy (which implies that pure and <*> satisfy the applicative functor laws).
A functor with application, providing operations to
  • embed pure expressions (pure), and
  • sequence computations and combine their results (<*> and liftA2).
A minimal complete definition must include implementations of pure and of either <*> or liftA2. If it defines both, then they must behave the same as their default definitions:
(<*>) = liftA2 id
liftA2 f x y = f <$> x <*> y
Further, any definition must satisfy the following: The other methods have the following default definitions, which may be overridden with equivalent specialized implementations: As a consequence of these laws, the Functor instance for f will satisfy It may be useful to note that supposing
forall x y. p (q x y) = f x . g y
it follows from the above that
liftA2 p (liftA2 q u v) = liftA2 f u . liftA2 g v
If f is also a Monad, it should satisfy (which implies that pure and <*> satisfy the applicative functor laws).
A functor with application, providing operations to
  • embed pure expressions (pure), and
  • sequence computations and combine their results (<*>).
A minimal complete definition must include implementations of these functions satisfying the following laws: The other methods have the following default definitions, which may be overridden with equivalent specialized implementations: As a consequence of these laws, the Functor instance for f will satisfy If f is also a Monad, it should satisfy (which implies that pure and <*> satisfy the applicative functor laws).
Equivalent of Applicative for rank 2 data types
Properties to check that the Applicative m satisfies the applicative properties
Applicative Argument
ApplicativeStmt represents an applicative expression built with <$> and <*>. It is generated by the renamer, and is desugared into the appropriate applicative expression by the desugarer, but it is intended to be invisible in error messages. For full details, see Note [ApplicativeDo] in GHC.Rename.Expr
Allows do-notation for types that are Applicative as well as Monad. When enabled, desugaring do notation tries to use (*) and fmap and join as far as possible.
A FunctorB with application, providing operations to:
  • embed an "empty" value (bpure)
  • align and combine values (bprod)
It should satisfy the following laws:
bmap ((Pair a b) -> Pair (f a) (g b)) (u `bprod' v) = bmap f u `bprod' bmap g v
  • Left and right identity
bmap ((Pair _ b) -> b) (bpure e `bprod' v) = v
bmap ((Pair a _) -> a) (u `bprod' bpure e) = u
  • Associativity
bmap ((Pair a (Pair b c)) -> Pair (Pair a b) c) (u `bprod' (v `bprod' w)) = (u `bprod' v) `bprod' w
It is to FunctorB in the same way as Applicative relates to Functor. For a presentation of Applicative as a monoidal functor, see Section 7 of Applicative Programming with Effects. There is a default implementation of bprod and bpure based on Generic. Intuitively, it works on types where the value of bpure is uniquely defined. This corresponds rougly to record types (in the presence of sums, there would be several candidates for bpure), where every field is either a Monoid or covered by the argument f.
A FunctorT with application, providing operations to:
  • embed an "empty" value (tpure)
  • align and combine values (tprod)
It should satisfy the following laws:
tmap ((Pair a b) -> Pair (f a) (g b)) (u `tprod' v) = tmap f u `tprod' tmap g v
  • Left and right identity
tmap ((Pair _ b) -> b) (tpure e `tprod' v) = v
tmap ((Pair a _) -> a) (u `tprod' tpure e) = u
  • Associativity
tmap ((Pair a (Pair b c)) -> Pair (Pair a b) c) (u `tprod' (v `tprod' w)) = (u `tprod' v) `tprod' w
It is to FunctorT in the same way is Applicative relates to Functor. For a presentation of Applicative as a monoidal functor, see Section 7 of Applicative Programming with Effects. There is a default implementation of tprod and tpure based on Generic. Intuitively, it works on types where the value of tpure is uniquely defined. This corresponds rougly to record types (in the presence of sums, there would be several candidates for tpure), where every field is either a Monoid or covered by the argument f.
ApplicativeStmt represents an applicative expression built with <$> and <*>. It is generated by the renamer, and is desugared into the appropriate applicative expression by the desugarer, but it is intended to be invisible in error messages. For full details, see Note [ApplicativeDo] in GHC.Rename.Expr
An alternative definition of applicative functors, as witnessed by ap and matchOne. This class is almost like Selective but has a strict constraint on t.
Applicative Argument
Applicative morphism properties
Standard test spec for properties of Applicative instances for values generated with GenValid instances Example usage:
applicativeSpecOnArbitrary @[]
Standard test spec for properties of Applicative instances for values generated with Arbitrary instances Example usage:
applicativeSpecOnArbitrary @[]
Standard test spec for properties of Applicative instances for values generated by given generators (and names for those generator). Unless you are building a specific regression test, you probably want to use the other applicativeSpec functions. Example usage:
applicativeSpecOnGens
@Maybe
@String
(pure "ABC")
"ABC"
(Just <$> pure "ABC")
"Just an ABC"
(pure Nothing)
"purely Nothing"
((++) <$> genValid)
"prepends"
(pure <$> ((++) <$> genValid))
"prepends in a Just"
(pure <$> (flip (++) <$> genValid))
"appends in a Just"