| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Profunctor.Bicartesian.Free
Contents
Synopsis
- newtype FreeBicartesian (p :: Type -> Type -> Type) a b = FreeBicartesian {
- runFreeBicartesian :: FreeCocartesian p a b
- liftF :: p a b -> FreeBicartesian p a b
- foldFree :: forall (q :: Type -> Type -> Type) (p :: Type -> Type -> Type). (Cartesian q, Cocartesian q) => (p :-> q) -> FreeBicartesian p :-> q
- type ProductOp (p :: Type -> Type -> Type) (q :: Type -> Type -> Type) (r :: Type -> Type -> Type) = forall a1 b1 a2 b2. p a1 b1 -> q a2 b2 -> r (a1, a2) (b1, b2)
- multF :: forall (p :: Type -> Type -> Type) (q :: Type -> Type -> Type) (r :: Type -> Type -> Type) a b a' b'. ProductOp p q r -> FreeCocartesian p a b -> FreeCocartesian q a' b' -> FreeCocartesian r (a, a') (b, b')
Documentation
newtype FreeBicartesian (p :: Type -> Type -> Type) a b Source #
Free Bicartesian profunctor (with caveat -- see below) a Cartesian profunctor.
Law issues:
can be thought of as a way to add FreeBicartesian pCocartesian operations
on by taking "formal sums" of multplie values of Cartesian pp a b.
Products on sums of multiple values are normalized to sum of products **as if** it satisfy both left and right distribution laws and zero laws. For example, the result of
(p1 +++ p2) *** (q1 +++ q2)
is normalized to
(p1 *** q1) +++ (p1 *** q2) +++ (p2 *** q1) +++ (p2 *** q2)
up to isomorphisms of parameters of these profunctors.
Because there are some profunctors which are both Cartesian and Cocartesian
but do not satisfy distributive laws,
interpreting FreeBicartesian into such a profunctor might cause a surprising behavior.
For example, does not satisfy right distribution,
inheriting Joker []Alternative [] does not.
>>>import Control.Applicative>>>let x = [id, id]>>>let y = [1]; z = [2]>>>x <*> (y <|> z)[1,2,1,2]>>>(x <*> y) <|> (x <*> z)[1,1,2,2]
With such non-distributive p, foldFree does not preserve
the Cartesian operations. The following equation does not have to hold.
-- Not necessarily holds! foldFree id (ps *** qs) == foldFree id ps *** foldFree id qs
It is guaranteed that preserves both foldFree fCartesian and
Cocartesian operations if it is intepreting into a Bicartesian profunctor,
in other words both Cartesian p and Cocartesian p which satisfy these additional laws.
Cocartesianinstance is commutative- Left zero, Right zero, Left distribution, Right distribution
There are no guarantees if any of these conditions are not met.
Constructors
| FreeBicartesian | |
Fields
| |
Instances
liftF :: p a b -> FreeBicartesian p a b Source #
foldFree :: forall (q :: Type -> Type -> Type) (p :: Type -> Type -> Type). (Cartesian q, Cocartesian q) => (p :-> q) -> FreeBicartesian p :-> q Source #
Interpret a FreeBicartesian p into a Bicartesian profunction q.
It is guaranteed that preserves both foldFree fCartesian and
Cocartesian operations if q is a Bicartesian profunctor.
There are no guarantees if any of extra laws to be a Bicartesian are not met.