| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Profunctor.Cartesian
Synopsis
- class Profunctor p => Cartesian (p :: Type -> Type -> Type) where
- prodDay :: forall (r :: Type -> Type -> Type) (p :: Type -> Type -> Type) (q :: Type -> Type -> Type). Cartesian r => (p :-> r) -> (q :-> r) -> Day (,) p q :-> r
- class Profunctor p => Cocartesian (p :: Type -> Type -> Type) where
- sumDay :: forall (r :: Type -> Type -> Type) (p :: Type -> Type -> Type) (q :: Type -> Type -> Type). Cocartesian r => (p :-> r) -> (q :-> r) -> Day Either p q :-> r
- pureDefault :: Cartesian p => b -> p a b
- proUnitDefault :: Applicative (p a) => p a ()
- liftA2Default :: Cartesian p => (a -> b -> c) -> p x a -> p x b -> p x c
- fanoutDefault :: (Profunctor p, Applicative (p a)) => p a b1 -> p a b2 -> p a (b1, b2)
- describeFinite :: forall (n :: Nat) p. (KnownNat n, Cartesian p, Cocartesian p) => p (Finite n) (Finite n)
- describeFiniteBits :: (FiniteBits a, Cartesian p, Cocartesian p) => p a a
- class Bifunctor p => Assoc (p :: Type -> Type -> Type) where
- class Swap (p :: Type -> Type -> Type) where
- swap :: p a b -> p b a
- unitL :: ((), a) -> a
- ununitL :: a -> ((), a)
- unitR :: (a, ()) -> a
- ununitR :: a -> (a, ())
- emptyL :: Either Void a -> a
- unemptyL :: a -> Either Void a
- emptyR :: Either a Void -> a
- unemptyR :: a -> Either a Void
- distL :: (Either a b, c) -> Either (a, c) (b, c)
- undistL :: Either (a, c) (b, c) -> (Either a b, c)
- distR :: (c, Either a b) -> Either (c, a) (c, b)
- undistR :: Either (c, a) (c, b) -> (c, Either a b)
Documentation
class Profunctor p => Cartesian (p :: Type -> Type -> Type) where Source #
Minimal complete definition
proUnit, (proProduct | (***) | (&&&))
Methods
Unit of the product.
The type of proUnit can be understood as proUnit' :: p () ()
treated to have more generally-typed p a () using lmap.
const () :: a -> ()
proUnit' :: p () ()
lmap (const ()) proUnit' :: p a ()
proProduct :: (a -> (a1, a2)) -> ((b1, b2) -> b) -> p a1 b1 -> p a2 b2 -> p a b Source #
(***) :: p a b -> p a' b' -> p (a, a') (b, b') Source #
Product of two profunctors
(&&&) :: p a b -> p a b' -> p a (b, b') Source #
Alternative way to define the product (pronounced "fan-out")
proPower :: forall (n :: Nat) a b. KnownNat n => p a b -> p (Finite n -> a) (Finite n -> b) Source #
Function from finite types can be constructed as iterated product.
There is a default implementaion, but it can be more efficient implementation.
Instances
| Cartesian Counting Source # | |
Defined in Data.Profunctor.Counting Methods proUnit :: Counting a () Source # proProduct :: (a -> (a1, a2)) -> ((b1, b2) -> b) -> Counting a1 b1 -> Counting a2 b2 -> Counting a b Source # (***) :: Counting a b -> Counting a' b' -> Counting (a, a') (b, b') Source # (&&&) :: Counting a b -> Counting a b' -> Counting a (b, b') Source # proPower :: forall (n :: Nat) a b. KnownNat n => Counting a b -> Counting (Finite n -> a) (Finite n -> b) Source # | |
| Cartesian Exhaust Source # | |
Defined in Data.Profunctor.Exhaust Methods proUnit :: Exhaust a () Source # proProduct :: (a -> (a1, a2)) -> ((b1, b2) -> b) -> Exhaust a1 b1 -> Exhaust a2 b2 -> Exhaust a b Source # (***) :: Exhaust a b -> Exhaust a' b' -> Exhaust (a, a') (b, b') Source # (&&&) :: Exhaust a b -> Exhaust a b' -> Exhaust a (b, b') Source # proPower :: forall (n :: Nat) a b. KnownNat n => Exhaust a b -> Exhaust (Finite n -> a) (Finite n -> b) Source # | |
| Cartesian FinFn Source # | |
Defined in Data.Profunctor.FinFn Methods proUnit :: FinFn a () Source # proProduct :: (a -> (a1, a2)) -> ((b1, b2) -> b) -> FinFn a1 b1 -> FinFn a2 b2 -> FinFn a b Source # (***) :: FinFn a b -> FinFn a' b' -> FinFn (a, a') (b, b') Source # (&&&) :: FinFn a b -> FinFn a b' -> FinFn a (b, b') Source # proPower :: forall (n :: Nat) a b. KnownNat n => FinFn a b -> FinFn (Finite n -> a) (Finite n -> b) Source # | |
| Cartesian p => Cartesian (FreeBicartesian p) Source # | |
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 # | |
| Cartesian (FreeCartesian p) Source # | |
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 (ForgetCocartesian p) Source # | |
Defined in Data.Profunctor.Cocartesian.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 # | |
| Cartesian p => Cartesian (Coyoneda p) Source # | |
Defined in Data.Profunctor.Cartesian Methods proUnit :: Coyoneda p a () Source # proProduct :: (a -> (a1, a2)) -> ((b1, b2) -> b) -> Coyoneda p a1 b1 -> Coyoneda p a2 b2 -> Coyoneda p a b Source # (***) :: Coyoneda p a b -> Coyoneda p a' b' -> Coyoneda p (a, a') (b, b') Source # (&&&) :: Coyoneda p a b -> Coyoneda p a b' -> Coyoneda p a (b, b') Source # proPower :: forall (n :: Nat) a b. KnownNat n => Coyoneda p a b -> Coyoneda p (Finite n -> a) (Finite n -> b) Source # | |
| Cartesian p => Cartesian (Yoneda p) Source # | |
Defined in Data.Profunctor.Cartesian Methods proUnit :: Yoneda p a () Source # proProduct :: (a -> (a1, a2)) -> ((b1, b2) -> b) -> Yoneda p a1 b1 -> Yoneda p a2 b2 -> Yoneda p a b Source # (***) :: Yoneda p a b -> Yoneda p a' b' -> Yoneda p (a, a') (b, b') Source # (&&&) :: Yoneda p a b -> Yoneda p a b' -> Yoneda p a (b, b') Source # proPower :: forall (n :: Nat) a b. KnownNat n => Yoneda p a b -> Yoneda p (Finite n -> a) (Finite n -> b) Source # | |
| Cartesian (Encoder a b) Source # | |
Defined in Data.Finitary.PolyRep Methods proUnit :: Encoder a b a0 () Source # proProduct :: (a0 -> (a1, a2)) -> ((b1, b2) -> b0) -> Encoder a b a1 b1 -> Encoder a b a2 b2 -> Encoder a b a0 b0 Source # (***) :: Encoder a b a0 b0 -> Encoder a b a' b' -> Encoder a b (a0, a') (b0, b') Source # (&&&) :: Encoder a b a0 b0 -> Encoder a b a0 b' -> Encoder a b a0 (b0, b') Source # proPower :: forall (n :: Nat) a0 b0. KnownNat n => Encoder a b a0 b0 -> Encoder a b (Finite n -> a0) (Finite n -> b0) Source # | |
| Cartesian (Encoder a b) Source # | |
Defined in Data.Finitary.TreeRep Methods proUnit :: Encoder a b a0 () Source # proProduct :: (a0 -> (a1, a2)) -> ((b1, b2) -> b0) -> Encoder a b a1 b1 -> Encoder a b a2 b2 -> Encoder a b a0 b0 Source # (***) :: Encoder a b a0 b0 -> Encoder a b a' b' -> Encoder a b (a0, a') (b0, b') Source # (&&&) :: Encoder a b a0 b0 -> Encoder a b a0 b' -> Encoder a b a0 (b0, b') Source # proPower :: forall (n :: Nat) a0 b0. KnownNat n => Encoder a b a0 b0 -> Encoder a b (Finite n -> a0) (Finite n -> b0) Source # | |
| Monoid r => Cartesian (Forget r :: Type -> Type -> Type) Source # | |
Defined in Data.Profunctor.Cartesian Methods proUnit :: Forget r a () Source # proProduct :: (a -> (a1, a2)) -> ((b1, b2) -> b) -> Forget r a1 b1 -> Forget r a2 b2 -> Forget r a b Source # (***) :: Forget r a b -> Forget r a' b' -> Forget r (a, a') (b, b') Source # (&&&) :: Forget r a b -> Forget r a b' -> Forget r a (b, b') Source # proPower :: forall (n :: Nat) a b. KnownNat n => Forget r a b -> Forget r (Finite n -> a) (Finite n -> b) Source # | |
| Applicative f => Cartesian (Star f) Source # | |
Defined in Data.Profunctor.Cartesian Methods proUnit :: Star f a () Source # proProduct :: (a -> (a1, a2)) -> ((b1, b2) -> b) -> Star f a1 b1 -> Star f a2 b2 -> Star f a b Source # (***) :: Star f a b -> Star f a' b' -> Star f (a, a') (b, b') Source # (&&&) :: Star f a b -> Star f a b' -> Star f a (b, b') Source # proPower :: forall (n :: Nat) a b. KnownNat n => Star f a b -> Star f (Finite n -> a) (Finite n -> b) Source # | |
| Cartesian (->) Source # | |
Defined in Data.Profunctor.Cartesian Methods proProduct :: (a -> (a1, a2)) -> ((b1, b2) -> b) -> (a1 -> b1) -> (a2 -> b2) -> a -> b Source # (***) :: (a -> b) -> (a' -> b') -> (a, a') -> (b, b') Source # (&&&) :: (a -> b) -> (a -> b') -> a -> (b, b') Source # proPower :: forall (n :: Nat) a b. KnownNat n => (a -> b) -> (Finite n -> a) -> (Finite n -> b) Source # | |
| Divisible f => Cartesian (Clown f :: Type -> Type -> Type) Source # | |
Defined in Data.Profunctor.Cartesian Methods proUnit :: Clown f a () Source # proProduct :: (a -> (a1, a2)) -> ((b1, b2) -> b) -> Clown f a1 b1 -> Clown f a2 b2 -> Clown f a b Source # (***) :: Clown f a b -> Clown f a' b' -> Clown f (a, a') (b, b') Source # (&&&) :: Clown f a b -> Clown f a b' -> Clown f a (b, b') Source # proPower :: forall (n :: Nat) a b. KnownNat n => Clown f a b -> Clown f (Finite n -> a) (Finite n -> b) Source # | |
| Applicative f => Cartesian (Joker f :: Type -> Type -> Type) Source # | |
Defined in Data.Profunctor.Cartesian Methods proUnit :: Joker f a () Source # proProduct :: (a -> (a1, a2)) -> ((b1, b2) -> b) -> Joker f a1 b1 -> Joker f a2 b2 -> Joker f a b Source # (***) :: Joker f a b -> Joker f a' b' -> Joker f (a, a') (b, b') Source # (&&&) :: Joker f a b -> Joker f a b' -> Joker f a (b, b') Source # proPower :: forall (n :: Nat) a b. KnownNat n => Joker f a b -> Joker f (Finite n -> a) (Finite n -> b) Source # | |
| (Cartesian p, Cartesian q) => Cartesian (Product p q) Source # | |
Defined in Data.Profunctor.Cartesian Methods proUnit :: Product p q a () Source # proProduct :: (a -> (a1, a2)) -> ((b1, b2) -> b) -> Product p q a1 b1 -> Product p q a2 b2 -> Product p q a b Source # (***) :: Product p q a b -> Product p q a' b' -> Product p q (a, a') (b, b') Source # (&&&) :: Product p q a b -> Product p q a b' -> Product p q a (b, b') Source # proPower :: forall (n :: Nat) a b. KnownNat n => Product p q a b -> Product p q (Finite n -> a) (Finite n -> b) Source # | |
| (Cartesian p, Cartesian q) => Cartesian (Procompose p q) Source # | |
Defined in Data.Profunctor.Cartesian Methods proUnit :: Procompose p q a () Source # proProduct :: (a -> (a1, a2)) -> ((b1, b2) -> b) -> Procompose p q a1 b1 -> Procompose p q a2 b2 -> Procompose p q a b Source # (***) :: Procompose p q a b -> Procompose p q a' b' -> Procompose p q (a, a') (b, b') Source # (&&&) :: Procompose p q a b -> Procompose p q a b' -> Procompose p q a (b, b') Source # proPower :: forall (n :: Nat) a b. KnownNat n => Procompose p q a b -> Procompose p q (Finite n -> a) (Finite n -> b) Source # | |
prodDay :: forall (r :: Type -> Type -> Type) (p :: Type -> Type -> Type) (q :: Type -> Type -> Type). Cartesian r => (p :-> r) -> (q :-> r) -> Day (,) p q :-> r Source #
class Profunctor p => Cocartesian (p :: Type -> Type -> Type) where Source #
Methods
Unit of the sum.
The type of proEmpty can be understood as proEmpty' :: p Void
treated to have more generally-typed Voidp Void b using rmap.
absurd:: Void -> b proEmpty' :: p Void Voidrmapabsurd proEmpty' :: p Void b
proSum :: (a -> Either a1 a2) -> (Either b1 b2 -> b) -> p a1 b1 -> p a2 b2 -> p a b Source #
(+++) :: p a b -> p a' b' -> p (Either a a') (Either b b') Source #
Sum of two profunctors
(|||) :: p a b -> p a' b -> p (Either a a') b Source #
Alternative way to define the sum (pronounced "fan-in")
proTimes :: forall (n :: Nat) a b. KnownNat n => p a b -> p (Finite n, a) (Finite n, b) Source #
Pairing with finite types can be constructed as iterated sum.
There is a default implementaion, but it can be more efficient implementation.
Instances
sumDay :: forall (r :: Type -> Type -> Type) (p :: Type -> Type -> Type) (q :: Type -> Type -> Type). Cocartesian r => (p :-> r) -> (q :-> r) -> Day Either p q :-> r Source #
Cartesian p iff forall x. Applicative (p x)
pureDefault :: Cartesian p => b -> p a b Source #
proUnitDefault :: Applicative (p a) => p a () Source #
liftA2Default :: Cartesian p => (a -> b -> c) -> p x a -> p x b -> p x c Source #
fanoutDefault :: (Profunctor p, Applicative (p a)) => p a b1 -> p a b2 -> p a (b1, b2) Source #
Utilities
describeFinite :: forall (n :: Nat) p. (KnownNat n, Cartesian p, Cocartesian p) => p (Finite n) (Finite n) Source #
describeFiniteBits :: (FiniteBits a, Cartesian p, Cocartesian p) => p a a Source #
Laws
Cartesian laws
Instances of Cartesian must satisfy the following equations.
- Left unit of
*** dimapununitLunitL(proUnit*** p) === p- Right unit of
*** dimapununitRunitR(p ***proUnit) === p- Associativity of
*** dimapassocunassoc((p *** q) *** r) === p *** (q *** r)
Some instance of Cartesian optionally satisfy the following equation.
- Commutativity of
*** dimapswapswap (p *** q) === q *** p
In this library, an instance of Cartesian is called commutative Cartesian
if it satisfy the above commutativity law.
Instances with and without commutativity
TODO fill here: most instance is not commutative, Counting or Forget r for commutative monoid is (positive)
Cocartesian laws
Instances of Cocartesian must satisfy the following equations.
- Left unit of
+++ dimapunemptyLemptyL(proEmpty+++ p) === p- Right unit of
+++ dimapunemptyRemptyR(p +++proEmpty) === p- Associativity of
+++ dimapassocunassoc((p +++ q) +++ r) === p +++ (q +++ r)
Some instance of Cocartesian optionally satisfy the following equation.
- Commutativity of
+++ dimapswapswap (p +++ q) === q +++ p
In this library, an instance of Cocartesian is called commutative Cocartesian
if it satisfy the above commutativity law.
Instances with and without commutativity
TODO fill here: Star f, Clown Equivalence (positive) and
Clown Comparison, Alternative f => Joker f (negative)
Optional laws for interaction of Cartesian and Cocartesian
If a Profunctor p is an instance of both Cartesian and Cocartesian,
there are few named properties they optionally satisfy.
- Left zero
dimap absurd (absurd . fst) (proEmpty *** p) === proEmpty- Left distribution
dimapundistLdistL((p +++ q) *** r) === (p *** r) +++ (q *** r)- Right zero
dimap absurd (absurd . snd) (p *** proEmpty) === proEmpty- Right distribution
dimapundistRdistR(r *** (p +++ q)) === (r *** p) +++ (r *** q)
In this library, an instance of both Cartesian and Cocartesian is called
- near-Bicartesian if it additionally satisfy Left zero and Left distribution
- Bicartesian if it is near-Bicartesian, is commutative
Cocartesian, and satisfy all four of Right zero and Right distribution. In other words, satisfy all of above four laws and commutativity of+++.
Instances with/without optional properties
TODO fill here
Note:
In usual mathematical abstract algebra context, it is common practice to name Right distributivity to mean Left zero and Left distibution combined, and same switching for Left distributivity.
The naming convention of this library came from Haskell convention
of describing distributive properties of Alternative
and MonadPlus.
https://wiki.haskell.org/index.php?title=Typeclassopedia#Laws_6
Type isomorphisms
Re-exports
class Bifunctor p => Assoc (p :: Type -> Type -> Type) where #
"Semigroup-y" Bifunctors.
assoc.unassoc=idunassoc.assoc=idassoc.bimap(bimapf g) h =bimapf (bimapg h) .assoc
This library doesn't provide Monoidal class, with left and right unitors.
Are they useful in practice?
class Swap (p :: Type -> Type -> Type) where #
Symmetric Bifunctors.
swap.swap=id
If p is a Bifunctor the following property is assumed to hold:
swap.bimapf g =bimapg f .swap
Swap isn't a subclass of Bifunctor, as for example
>>>newtype Bipredicate a b = Bipredicate (a -> b -> Bool)
is not a Bifunctor but has Swap instance
>>>instance Swap Bipredicate where swap (Bipredicate p) = Bipredicate (flip p)
Instances
| Swap Either # | |
Defined in Data.Bifunctor.Swap | |
| Swap (,) # | |
Defined in Data.Bifunctor.Swap | |
| Swap ((,,) x) # | |
Defined in Data.Bifunctor.Swap | |
| Swap ((,,,) x y) # | |
Defined in Data.Bifunctor.Swap | |
| Swap p => Swap (Flip p) # | Since: bifunctors-5.6.1 |
Defined in Data.Bifunctor.Flip | |
| Swap ((,,,,) x y z) # | |
Defined in Data.Bifunctor.Swap | |
| (Swap p, Swap q) => Swap (Product p q) # | Since: bifunctors-5.6.1 |
Defined in Data.Bifunctor.Product | |
| (Swap p, Swap q) => Swap (Sum p q) # | Since: bifunctors-5.6.1 |
Defined in Data.Bifunctor.Sum | |
| Swap ((,,,,,) x y z w) # | |
Defined in Data.Bifunctor.Swap | |
| (Functor f, Swap p) => Swap (Tannen f p) # | Since: bifunctors-5.6.1 |
Defined in Data.Bifunctor.Tannen | |
| Swap ((,,,,,,) x y z w v) # | |
Defined in Data.Bifunctor.Swap | |
| (f ~ g, Functor f, Swap p) => Swap (Biff p f g) # | Since: bifunctors-5.6.1 |
Defined in Data.Bifunctor.Biff | |