cartesian-profunctors
Safe HaskellNone
LanguageHaskell2010

Data.Profunctor.Cartesian.Free

Synopsis

Documentation

data FreeMonoidal (t :: Type -> Type -> Type) i (p :: Type -> Type -> Type) a b Source #

Constructs free monoidal profunctor with specified monoid. Each parameters of FreeMonoidal t i p stands for:

  • t for the monoidal product
  • i for the unit of the monoidal product t
  • p for the profunctor generating FreeMonoidal

For example, FreeMonoidal (,) () p is the free Cartesian profunctor.

Constructors

Neutral (a -> i) (i -> b) 
Cons (Day t p (FreeMonoidal t i p) a b) 

Instances

Instances details
ProfunctorMonad FreeCartesian Source # 
Instance details

Defined in Data.Profunctor.Cartesian.Free

Methods

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

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

ProfunctorMonad FreeCocartesian Source # 
Instance details

Defined in Data.Profunctor.Cartesian.Free

Methods

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

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

ProfunctorFunctor (FreeMonoidal t i :: (Type -> Type -> Type) -> Type -> Type -> Type) Source # 
Instance details

Defined in Data.Profunctor.Cartesian.Free

Methods

promap :: forall (p :: Type -> Type -> Type) (q :: Type -> Type -> Type). Profunctor p => (p :-> q) -> FreeMonoidal t i p :-> FreeMonoidal t i q #

Cartesian (FreeCartesian p) Source # 
Instance details

Defined in Data.Profunctor.Cartesian.Free

Methods

proUnit :: FreeCartesian p a () Source #

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

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

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

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

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

Defined in Data.Profunctor.Cartesian.Free

Methods

proUnit :: FreeCocartesian p a () Source #

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

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

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

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

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

Defined in Data.Profunctor.Cartesian.Free

Methods

proEmpty :: FreeCocartesian p Void b Source #

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

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

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

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

Profunctor (FreeMonoidal t i p) Source # 
Instance details

Defined in Data.Profunctor.Cartesian.Free

Methods

dimap :: (a -> b) -> (c -> d) -> FreeMonoidal t i p b c -> FreeMonoidal t i p a d #

lmap :: (a -> b) -> FreeMonoidal t i p b c -> FreeMonoidal t i p a c #

rmap :: (b -> c) -> FreeMonoidal t i p a b -> FreeMonoidal t i p a c #

(#.) :: forall a b c q. Coercible c b => q b c -> FreeMonoidal t i p a b -> FreeMonoidal t i p a c #

(.#) :: forall a b c q. Coercible b a => FreeMonoidal t i p b c -> q a b -> FreeMonoidal t i p a c #

Functor (FreeMonoidal t i p a) Source # 
Instance details

Defined in Data.Profunctor.Cartesian.Free

Methods

fmap :: (a0 -> b) -> FreeMonoidal t i p a a0 -> FreeMonoidal t i p a b #

(<$) :: a0 -> FreeMonoidal t i p a b -> FreeMonoidal t i p a a0 #

type FreeCartesian = FreeMonoidal (,) () Source #

Free Cartesian profunctor is FreeMonoidal profunctor with respect to (,).

foldFreeCartesian :: forall (q :: Type -> Type -> Type) (p :: Type -> Type -> Type). Cartesian q => (p :-> q) -> FreeCartesian p :-> q Source #

type FreeCocartesian = FreeMonoidal Either Void Source #

Free Cocartesian profunctor is FreeMonoidal profunctor with respect to Either.

Caution about Cartesian instance

Note that FreeCocartesian p have an instance of Cartesian, by distributing product on sums to sum of products of individual profunctors. When it is desirable to disable Cartesian instance of FreeCocartesian p, use ForgetCartesian to ignore Cartesian instance of p.

Because there are some profunctors which are both Cartesian and Cocartesian but do not satisfy distributive laws, using FreeCocartesian with such profunctors might cause a surprising behavior.

For example, Joker [] is not distributive, as Alternative [] is not distributive as shown below.

>>> 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 Cartesian p, foldFreeCocartesian does not preserve the Cartesian operations. The following equation does not have to hold.

-- Not necessarily holds!
foldFreeCocartesian id (ps *** qs)
 == foldFreeCocartesian id ps *** foldFreeCocartesian id qs

foldFreeCocartesian :: forall (q :: Type -> Type -> Type) (p :: Type -> Type -> Type). Cocartesian q => (p :-> q) -> FreeCocartesian p :-> q Source #

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

Forgets Cartesian instance from a Profunctor.

Constructors

ForgetCartesian 

Fields

Instances

Instances details
Cocartesian p => Cocartesian (ForgetCartesian p) Source # 
Instance details

Defined in Data.Profunctor.Cartesian.Free

Methods

proEmpty :: ForgetCartesian p Void b Source #

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

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

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

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

Profunctor p => Profunctor (ForgetCartesian p) Source # 
Instance details

Defined in Data.Profunctor.Cartesian.Free

Methods

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

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

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

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

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

Functor (p a) => Functor (ForgetCartesian p a) Source # 
Instance details

Defined in Data.Profunctor.Cartesian.Free

Methods

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

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

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

Forgets Cocartesian instance from a Profunctor.

Constructors

ForgetCocartesian 

Fields

Instances

Instances details
Cartesian p => Cartesian (ForgetCocartesian p) Source # 
Instance details

Defined in Data.Profunctor.Cartesian.Free

Methods

proUnit :: ForgetCocartesian p a () Source #

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

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

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

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

Profunctor p => Profunctor (ForgetCocartesian p) Source # 
Instance details

Defined in Data.Profunctor.Cartesian.Free

Methods

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

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

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

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

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

Functor (p a) => Functor (ForgetCocartesian p a) Source # 
Instance details

Defined in Data.Profunctor.Cartesian.Free

Methods

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

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