cartesian-profunctors
Safe HaskellNone
LanguageHaskell2010

Data.Profunctor.Bicartesian.Free

Contents

Synopsis

Documentation

newtype FreeBicartesian (p :: Type -> Type -> Type) a b Source #

Free Bicartesian profunctor (with caveat -- see below) a Cartesian profunctor.

Law issues:

FreeBicartesian p can be thought of as a way to add Cocartesian operations on Cartesian p by taking "formal sums" of multplie values of p 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, Joker [] does not satisfy right distribution, inheriting 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 foldFree f preserves both Cartesian 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.

  • Cocartesian instance is commutative
  • Left zero, Right zero, Left distribution, Right distribution

There are no guarantees if any of these conditions are not met.

Constructors

FreeBicartesian 

Instances

Instances details
ProfunctorMonad FreeBicartesian Source # 
Instance details

Defined in Data.Profunctor.Bicartesian.Free

Methods

proreturn :: forall (p :: Type -> Type -> Type). Profunctor p => p :-> FreeBicartesian p #

projoin :: forall (p :: Type -> Type -> Type). Profunctor p => FreeBicartesian (FreeBicartesian p) :-> FreeBicartesian p #

ProfunctorFunctor FreeBicartesian Source # 
Instance details

Defined in Data.Profunctor.Bicartesian.Free

Methods

promap :: forall (p :: Type -> Type -> Type) (q :: Type -> Type -> Type). Profunctor p => (p :-> q) -> FreeBicartesian p :-> FreeBicartesian q #

Cartesian p => Cartesian (FreeBicartesian p) Source # 
Instance details

Defined in Data.Profunctor.Bicartesian.Free

Methods

proUnit :: FreeBicartesian p a () Source #

proProduct :: (a -> (a1, a2)) -> ((b1, b2) -> b) -> FreeBicartesian p a1 b1 -> FreeBicartesian p a2 b2 -> FreeBicartesian p a b Source #

(***) :: FreeBicartesian p a b -> FreeBicartesian p a' b' -> FreeBicartesian p (a, a') (b, b') Source #

(&&&) :: FreeBicartesian p a b -> FreeBicartesian p a b' -> FreeBicartesian p a (b, b') Source #

proPower :: forall (n :: Nat) a b. KnownNat n => FreeBicartesian p a b -> FreeBicartesian p (Finite n -> a) (Finite n -> b) Source #

Profunctor p => Cocartesian (FreeBicartesian p) Source # 
Instance details

Defined in Data.Profunctor.Bicartesian.Free

Methods

proEmpty :: FreeBicartesian p Void b Source #

proSum :: (a -> Either a1 a2) -> (Either b1 b2 -> b) -> FreeBicartesian p a1 b1 -> FreeBicartesian p a2 b2 -> FreeBicartesian p a b Source #

(+++) :: FreeBicartesian p a b -> FreeBicartesian p a' b' -> FreeBicartesian p (Either a a') (Either b b') Source #

(|||) :: FreeBicartesian p a b -> FreeBicartesian p a' b -> FreeBicartesian p (Either a a') b Source #

proTimes :: forall (n :: Nat) a b. KnownNat n => FreeBicartesian p a b -> FreeBicartesian p (Finite n, a) (Finite n, b) Source #

Profunctor (FreeBicartesian p) Source # 
Instance details

Defined in Data.Profunctor.Bicartesian.Free

Methods

dimap :: (a -> b) -> (c -> d) -> FreeBicartesian p b c -> FreeBicartesian p a d #

lmap :: (a -> b) -> FreeBicartesian p b c -> FreeBicartesian p a c #

rmap :: (b -> c) -> FreeBicartesian p a b -> FreeBicartesian p a c #

(#.) :: forall a b c q. Coercible c b => q b c -> FreeBicartesian p a b -> FreeBicartesian p a c #

(.#) :: forall a b c q. Coercible b a => FreeBicartesian p b c -> q a b -> FreeBicartesian p a c #

Cartesian p => Applicative (FreeBicartesian p a) Source # 
Instance details

Defined in Data.Profunctor.Bicartesian.Free

Methods

pure :: a0 -> FreeBicartesian p a a0 #

(<*>) :: FreeBicartesian p a (a0 -> b) -> FreeBicartesian p a a0 -> FreeBicartesian p a b #

liftA2 :: (a0 -> b -> c) -> FreeBicartesian p a a0 -> FreeBicartesian p a b -> FreeBicartesian p a c #

(*>) :: FreeBicartesian p a a0 -> FreeBicartesian p a b -> FreeBicartesian p a b #

(<*) :: FreeBicartesian p a a0 -> FreeBicartesian p a b -> FreeBicartesian p a a0 #

Functor (FreeBicartesian p a) Source # 
Instance details

Defined in Data.Profunctor.Bicartesian.Free

Methods

fmap :: (a0 -> b) -> FreeBicartesian p a a0 -> FreeBicartesian p a b #

(<$) :: a0 -> FreeBicartesian p a b -> FreeBicartesian p a a0 #

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 foldFree f preserves both Cartesian 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.

Utilities

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) Source #

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') Source #