ProductProfunctor is a generalization of Applicative. It has the usual Applicative "output" (covariant) parameter on the right. Additionally it has an "input" (contravariant) type parameter on the left.
The methods for ProductProfunctor correspond closely to those for Applicative as laid out in the following table. The only difference between them is that the ProductProfunctor has a contravariant type parameter on the left. We can use the contravariant to compose them in nice ways as described at Data.Profunctor.Product.
| Correspondence between Applicative and ProductProfunctor
|
| Applicative f ProductProfunctor p
|
| pure purePP
| :: b -> f b :: b -> p a b
|
| (<$>) (***$)
| :: (b -> b') :: (b -> b')
| -> f b -> p a b
| -> f b' -> p a b'
|
| (<*>) (****)
| :: f (b -> b') :: p a (b -> b')
| -> f b -> p a b
| -> f b' -> p a b'
If p is an instance of ProductProfunctor then p a a'
represents a sort of process for turning as into a's that can
be "laid out side-by-side" with other values of p to form "wider"
processes. For example, if I have
p :: p a x -- a process for turning as into xs
q :: p b y -- a process for turning bs into ys
r :: p c z -- a process for turning cs into zs
then I can combine them using p3 to get
p3 p q r :: p (a, b, c) (x, y, z)
-- a process for turning (a, b, c)s into (x, y, z)s
You would typically compose ProductProfunctors using
Profunctors's lmap and Applicative's pure,
<$> / fmap and <*>.
It's easy to make instances of ProductProfunctor. Just make instances
instance Profunctor MyProductProfunctor where
...
instance Applicative (MyProductProfunctor a) where
...
and then write
instance ProductProfunctor MyProductProfunctor where
purePP = pure
(****) = (<*>)
Methods
purePP :: b -> p a bpurePP is the generalisation of
Applicative's pure.(You probably won't need to use this except to define ProductProfunctor instances. In your own code
pureshould be sufficient.)(****) :: p a (b -> c) -> p a b -> p a c**** is the generalisation of
Applicative's <*>.(You probably won't need to use this except to define ProductProfunctor instances. In your own code
<*>should be sufficient.)empty :: p () ()Use
pure ()instead.emptymay be deprecated in a future version.(***!) :: p a b -> p a' b' -> p (a, a') (b, b')Use
\f g -> (,)instead.Control.Applicative.<$>Data.Profunctor.lmapfst f <*>Data.Profunctor.lmapsnd g(***!)may be deprecated in a future version.
Instances16ProductProfunctor, …
ProductProfunctor ZipperDefined in product-profunctors-0.11.1.1 · Data.Profunctor.Product.ExamplesApplicative f => ProductProfunctor (Traverse f)Defined in product-profunctors-0.11.1.1 · Data.Profunctor.Product.ExamplesProductProfunctor TaggedDefined in product-profunctors-0.11.1.1 · Data.Profunctor.Product · orphanProductProfunctor (Take a)Defined in product-profunctors-0.11.1.1 · Data.Profunctor.Product.ExamplesApplicative f => ProductProfunctor (Replicator r f)Defined in product-profunctors-0.11.1.1 · Data.Profunctor.Product.ExamplesApplicative f => ProductProfunctor (Star f)Defined in product-profunctors-0.11.1.1 · Data.Profunctor.Product · orphanFunctor f => ProductProfunctor (Costar f)Defined in product-profunctors-0.11.1.1 · Data.Profunctor.Product · orphanMonoid r => ProductProfunctor (Forget r)Defined in product-profunctors-0.11.1.1 · Data.Profunctor.Product · orphanProductProfunctor (->)Defined in product-profunctors-0.11.1.1 · Data.Profunctor.Product · orphanDivisible f => ProductProfunctor (Clown f)Defined in product-profunctors-0.11.1.1 · Data.Profunctor.Product · orphanApplicative f => ProductProfunctor (Joker f)Defined in product-profunctors-0.11.1.1 · Data.Profunctor.Product · orphanArrow arr => ProductProfunctor (WrappedArrow arr)Defined in product-profunctors-0.11.1.1 · Data.Profunctor.Product · orphan(ProductProfunctor p, ProductProfunctor q) => ProductProfunctor (Product p q)Defined in product-profunctors-0.11.1.1 · Data.Profunctor.Product · orphan(Applicative f, ProductProfunctor p) => ProductProfunctor (Tannen f p)Defined in product-profunctors-0.11.1.1 · Data.Profunctor.Product · orphan(ProductProfunctor p, ProductProfunctor q) => ProductProfunctor (Procompose p q)Defined in product-profunctors-0.11.1.1 · Data.Profunctor.Product · orphan(Functor f, Applicative g, ProductProfunctor p) => ProductProfunctor (Biff p f g)Defined in product-profunctors-0.11.1.1 · Data.Profunctor.Product · orphan