ap

In many situations, the liftM operations can be replaced by uses of ap, which promotes function application.
return f `ap` x1 `ap` ... `ap` xn
is equivalent to
liftM<n> f x1 x2 ... xn

Examples

>>> pure (\x y z -> x + y * z) `ap` Just 1 `ap` Just 5 `ap` Just 10
Just 51
In many situations, the liftM operations can be replaced by uses of ap, which promotes function application.
return f `ap` x1 `ap` ... `ap` xn
is equivalent to
liftMn f x1 x2 ... xn
Finds the articulation points for a connected undirected graph, by using the low numbers criteria: a) The root node is an articulation point iff it has two or more children. b) An non-root node v is an articulation point iff there exists at least one child w of v such that lowNumber(w) >= dfsNumber(v).
Sequential application. Equivalent to Control.Applicative.<*>.
Like ap, but evaluating the function and its argument in parallel.
Recover the application operator <*> from matchOne.
Alphabetical synonym for <*>
An adjective phrase. Transitive (fond of Mary, interested in an account) or intransitive (correct, green, valid).
In many situations, the liftM operations can be replaced by uses of ap, which promotes function application.
return f `ap` x1 `ap` ... `ap` xn
is equivalent to
liftMn f x1 x2 ... xn
This data type witnesses the lifting of a Monoid into an Applicative pointwise.

Examples

>>> Ap (Just [1, 2, 3]) <> Ap Nothing
Ap {getAp = Nothing}
>>> Ap [Sum 10, Sum 20] <> Ap [Sum 1, Sum 2]
Ap {getAp = [Sum {getSum = 11},Sum {getSum = 12},Sum {getSum = 21},Sum {getSum = 22}]}
Monoid generated by liftA2 (<>) Starting from GHC 8.6, a similar type is available from Data.Monoid. This type is nevertheless kept for compatibility.
The free Applicative for a Functor f.
The faster free Applicative.
The free Applicative for a Functor f.
The free Applicative for a Functor f.
"Applicative Effects in Free Monads" Often times, the (\<*\>) operator can be more efficient than ap. Conventional free monads don't provide any means of modeling this. The free monad can be modified to make use of an underlying applicative. But it does require some laws, or else the (\<*\>) = ap law is broken. When interpreting this free monad with foldFree, the natural transformation must be an applicative homomorphism. An applicative homomorphism hm :: (Applicative f, Applicative g) => f x -> g x will satisfy these laws.
  • hm (pure a) = pure a
  • hm (f <*> a) = hm f <*> hm a
This is based on the "Applicative Effects in Free Monads" series of articles by Will Fancher