profunctors-5.2.1: Profunctors

Copyright | (C) 2014-2015 Edward Kmett
License | BSD-style (see the file LICENSE)
Maintainer | Edward Kmett <ekmett@gmail.com>
Stability | provisional
Portability | Rank2Types
Safe Haskell | Safe
Language | Haskell2010

Data.Profunctor.Choice

Contents

- Strength
- Costrength

Description

Synopsis

- class Profunctor p => Choice p where
- newtype TambaraSum p a b = TambaraSum {
  - runTambaraSum :: forall c. p (Either a c) (Either b c)
  }
- tambaraSum :: Choice p => (p :-> q) -> p :-> TambaraSum q
- untambaraSum :: Profunctor q => (p :-> TambaraSum q) -> p :-> q
- data PastroSum p a b where
  - PastroSum :: (Either y z -> b) -> p x y -> (a -> Either x z) -> PastroSum p a b
- class Profunctor p => Cochoice p where
- data CotambaraSum q a b where
  - CotambaraSum :: Cochoice r => (r :-> q) -> r a b -> CotambaraSum q a b
- cotambaraSum :: Cochoice p => (p :-> q) -> p :-> CotambaraSum q
- uncotambaraSum :: Profunctor q => (p :-> CotambaraSum q) -> p :-> q
- newtype CopastroSum p a b = CopastroSum {
  - runCopastroSum :: forall r. Cochoice r => (forall x y. p x y -> r x y) -> r a b
  }

# Strength

class Profunctor p => Choice p where Source #

The generalization of `Costar` of `Functor` that is strong with respect to `Either`.

Note: This is also a notion of strength, except with regards to another monoidal structure that we can choose to equip Hask with: the cocartesian coproduct.

Minimal complete definition

left' | right'

Methods

left' :: p a b -> p (Either a c) (Either b c) Source #

Laws:

    left' ≡ dimap swapE swapE . right' where
      swapE :: Either a b -> Either b a
      swapE = either Right Left
    rmap Left ≡ lmap Left . left'
    lmap (right f) . left' ≡ rmap (right f) . left'
    left' . left' ≡ dimap assocE unassocE . left' where
      assocE :: Either (Either a b) c -> Either a (Either b c)
      assocE (Left (Left a)) = Left a
      assocE (Left (Right b)) = Right (Left b)
      assocE (Right c) = Right (Right c)
      unassocE :: Either a (Either b c) -> Either (Either a b) c
      unassocE (Left a) = Left (Left a)
      unassocE (Right (Left b) = Left (Right b)
      unassocE (Right (Right c)) = Right c)

right' :: p a b -> p (Either c a) (Either c b) Source #

Laws:

    right' ≡ dimap swapE swapE . left' where
      swapE :: Either a b -> Either b a
      swapE = either Right Left
    rmap Right ≡ lmap Right . right'
    lmap (left f) . right' ≡ rmap (left f) . right'
    right' . right' ≡ dimap unassocE assocE . right' where
      assocE :: Either (Either a b) c -> Either a (Either b c)
      assocE (Left (Left a)) = Left a
      assocE (Left (Right b)) = Right (Left b)
      assocE (Right c) = Right (Right c)
      unassocE :: Either a (Either b c) -> Either (Either a b) c
      unassocE (Left a) = Left (Left a)
      unassocE (Right (Left b) = Left (Right b)
      unassocE (Right (Right c)) = Right c)

Instances

Choice (->) Source # |
Methods left' :: (a -> b) -> Either a c -> Either b c Source # right' :: (a -> b) -> Either c a -> Either c b Source #
Monad m => Choice (Kleisli m) Source # |
Methods left' :: Kleisli m a b -> Kleisli m (Either a c) (Either b c) Source # right' :: Kleisli m a b -> Kleisli m (Either c a) (Either c b) Source #
Comonad w => Choice (Cokleisli w) Source # | `extract` approximates `costrength`
Methods left' :: Cokleisli w a b -> Cokleisli w (Either a c) (Either b c) Source # right' :: Cokleisli w a b -> Cokleisli w (Either c a) (Either c b) Source #
Choice (Tagged *) Source # |
Methods left' :: Tagged * a b -> Tagged * (Either a c) (Either b c) Source # right' :: Tagged * a b -> Tagged * (Either c a) (Either c b) Source #
Monoid r => Choice (Forget r) Source # |
Methods left' :: Forget r a b -> Forget r (Either a c) (Either b c) Source # right' :: Forget r a b -> Forget r (Either c a) (Either c b) Source #
ArrowChoice p => Choice (WrappedArrow p) Source # |
Methods left' :: WrappedArrow p a b -> WrappedArrow p (Either a c) (Either b c) Source # right' :: WrappedArrow p a b -> WrappedArrow p (Either c a) (Either c b) Source #
Traversable w => Choice (Costar w) Source # |
Methods left' :: Costar w a b -> Costar w (Either a c) (Either b c) Source # right' :: Costar w a b -> Costar w (Either c a) (Either c b) Source #
Applicative f => Choice (Star f) Source # |
Methods left' :: Star f a b -> Star f (Either a c) (Either b c) Source # right' :: Star f a b -> Star f (Either c a) (Either c b) Source #
Choice p => Choice (Tambara p) Source # |
Methods left' :: Tambara p a b -> Tambara p (Either a c) (Either b c) Source # right' :: Tambara p a b -> Tambara p (Either c a) (Either c b) Source #
Choice (PastroSum p) Source # |
Methods left' :: PastroSum p a b -> PastroSum p (Either a c) (Either b c) Source # right' :: PastroSum p a b -> PastroSum p (Either c a) (Either c b) Source #
Profunctor p => Choice (TambaraSum p) Source # |
Methods left' :: TambaraSum p a b -> TambaraSum p (Either a c) (Either b c) Source # right' :: TambaraSum p a b -> TambaraSum p (Either c a) (Either c b) Source #
Choice (FreeTraversing p) Source # |
Methods left' :: FreeTraversing p a b -> FreeTraversing p (Either a c) (Either b c) Source # right' :: FreeTraversing p a b -> FreeTraversing p (Either c a) (Either c b) Source #
Profunctor p => Choice (CofreeTraversing p) Source # |
Methods left' :: CofreeTraversing p a b -> CofreeTraversing p (Either a c) (Either b c) Source # right' :: CofreeTraversing p a b -> CofreeTraversing p (Either c a) (Either c b) Source #
Choice (FreeMapping p) Source # |
Methods left' :: FreeMapping p a b -> FreeMapping p (Either a c) (Either b c) Source # right' :: FreeMapping p a b -> FreeMapping p (Either c a) (Either c b) Source #
Profunctor p => Choice (CofreeMapping p) Source # |
Methods left' :: CofreeMapping p a b -> CofreeMapping p (Either a c) (Either b c) Source # right' :: CofreeMapping p a b -> CofreeMapping p (Either c a) (Either c b) Source #
Choice p => Choice (Coyoneda p) Source # |
Methods left' :: Coyoneda p a b -> Coyoneda p (Either a c) (Either b c) Source # right' :: Coyoneda p a b -> Coyoneda p (Either c a) (Either c b) Source #
Choice p => Choice (Yoneda p) Source # |
Methods left' :: Yoneda p a b -> Yoneda p (Either a c) (Either b c) Source # right' :: Yoneda p a b -> Yoneda p (Either c a) (Either c b) Source #
(Functor f, Choice p) => Choice (Cayley f p) Source # |
Methods left' :: Cayley f p a b -> Cayley f p (Either a c) (Either b c) Source # right' :: Cayley f p a b -> Cayley f p (Either c a) (Either c b) Source #
(Choice p, Choice q) => Choice (Procompose p q) Source # |
Methods left' :: Procompose p q a b -> Procompose p q (Either a c) (Either b c) Source # right' :: Procompose p q a b -> Procompose p q (Either c a) (Either c b) Source #
Functor f => Choice (Joker * * f) Source # |
Methods left' :: Joker * * f a b -> Joker * * f (Either a c) (Either b c) Source # right' :: Joker * * f a b -> Joker * * f (Either c a) (Either c b) Source #
(Choice p, Choice q) => Choice (Product * * p q) Source # |
Methods left' :: Product * * p q a b -> Product * * p q (Either a c) (Either b c) Source # right' :: Product * * p q a b -> Product * * p q (Either c a) (Either c b) Source #
(Functor f, Choice p) => Choice (Tannen * * * f p) Source # |
Methods left' :: Tannen * * * f p a b -> Tannen * * * f p (Either a c) (Either b c) Source # right' :: Tannen * * * f p a b -> Tannen * * * f p (Either c a) (Either c b) Source #

newtype TambaraSum p a b Source #

TambaraSum is cofreely adjoins strength with respect to Either.

Note: this is not dual to `Tambara`. It is `Tambara` with respect to a different tensor.

Constructors

TambaraSum |

Fields

- runTambaraSum :: forall c. p (Either a c) (Either b c)

Instances

ProfunctorComonad TambaraSum Source # |
Methods proextract :: Profunctor p => TambaraSum p :-> p Source # produplicate :: Profunctor p => TambaraSum p :-> TambaraSum (TambaraSum p) Source #
ProfunctorFunctor TambaraSum Source # |
Methods promap :: Profunctor p => (p :-> q) -> TambaraSum p :-> TambaraSum q Source #
ProfunctorAdjunction PastroSum TambaraSum Source # |
Methods unit :: Profunctor p => p :-> TambaraSum (PastroSum p) Source # counit :: Profunctor p => PastroSum (TambaraSum p) :-> p Source #
Profunctor p => Profunctor (TambaraSum p) Source # |
Methods dimap :: (a -> b) -> (c -> d) -> TambaraSum p b c -> TambaraSum p a d Source # lmap :: (a -> b) -> TambaraSum p b c -> TambaraSum p a c Source # rmap :: (b -> c) -> TambaraSum p a b -> TambaraSum p a c Source # (#.) :: Coercible * c b => (b -> c) -> TambaraSum p a b -> TambaraSum p a c Source # (.#) :: Coercible * b a => TambaraSum p b c -> (a -> b) -> TambaraSum p a c Source #
Profunctor p => Choice (TambaraSum p) Source # |
Methods left' :: TambaraSum p a b -> TambaraSum p (Either a c) (Either b c) Source # right' :: TambaraSum p a b -> TambaraSum p (Either c a) (Either c b) Source #
Category * p => Category * (TambaraSum p) Source # |
Methods id :: cat a a # (.) :: cat b c -> cat a b -> cat a c #
Profunctor p => Functor (TambaraSum p a) Source # |
Methods fmap :: (a -> b) -> TambaraSum p a a -> TambaraSum p a b # (<$) :: a -> TambaraSum p a b -> TambaraSum p a a #

tambaraSum :: Choice p => (p :-> q) -> p :-> TambaraSum q Source #

    tambaraSum . untambaraSum ≡ id
    untambaraSum . tambaraSum ≡ id

untambaraSum :: Profunctor q => (p :-> TambaraSum q) -> p :-> q Source #

    tambaraSum . untambaraSum ≡ id
    untambaraSum . tambaraSum ≡ id

data PastroSum p a b where Source #

PastroSum -| TambaraSum

PastroSum freely constructs strength with respect to Either.

Constructors

PastroSum :: (Either y z -> b) -> p x y -> (a -> Either x z) -> PastroSum p a b |

Instances

ProfunctorMonad PastroSum Source # |
Methods proreturn :: Profunctor p => p :-> PastroSum p Source # projoin :: Profunctor p => PastroSum (PastroSum p) :-> PastroSum p Source #
ProfunctorFunctor PastroSum Source # |
Methods promap :: Profunctor p => (p :-> q) -> PastroSum p :-> PastroSum q Source #
ProfunctorAdjunction PastroSum TambaraSum Source # |
Methods unit :: Profunctor p => p :-> TambaraSum (PastroSum p) Source # counit :: Profunctor p => PastroSum (TambaraSum p) :-> p Source #
Profunctor (PastroSum p) Source # |
Methods dimap :: (a -> b) -> (c -> d) -> PastroSum p b c -> PastroSum p a d Source # lmap :: (a -> b) -> PastroSum p b c -> PastroSum p a c Source # rmap :: (b -> c) -> PastroSum p a b -> PastroSum p a c Source # (#.) :: Coercible * c b => (b -> c) -> PastroSum p a b -> PastroSum p a c Source # (.#) :: Coercible * b a => PastroSum p b c -> (a -> b) -> PastroSum p a c Source #
Choice (PastroSum p) Source # |
Methods left' :: PastroSum p a b -> PastroSum p (Either a c) (Either b c) Source # right' :: PastroSum p a b -> PastroSum p (Either c a) (Either c b) Source #

# Costrength

class Profunctor p => Cochoice p where Source #

Minimal complete definition

unleft | unright

Methods

unleft :: p (Either a d) (Either b d) -> p a b Source #

Laws:

    unleft ≡ unright . dimap swapE swapE where
      swapE :: Either a b -> Either b a
      swapE = either Right Left
    rmap (either id absurd) ≡ unleft . lmap (either id absurd)
    unfirst . rmap (second f) ≡ unfirst . lmap (second f)
    unleft . unleft ≡ unleft . dimap assocE unassocE where
      assocE :: Either (Either a b) c -> Either a (Either b c)
      assocE (Left (Left a)) = Left a
      assocE (Left (Right b)) = Right (Left b)
      assocE (Right c) = Right (Right c)
      unassocE :: Either a (Either b c) -> Either (Either a b) c
      unassocE (Left a) = Left (Left a)
      unassocE (Right (Left b) = Left (Right b)
      unassocE (Right (Right c)) = Right c)

unright :: p (Either d a) (Either d b) -> p a b Source #

Laws:

    unright ≡ unleft . dimap swapE swapE where
      swapE :: Either a b -> Either b a
      swapE = either Right Left
    rmap (either absurd id) ≡ unright . lmap (either absurd id)
    unsecond . rmap (first f) ≡ unsecond . lmap (first f)
    unright . unright ≡ unright . dimap unassocE assocE where
      assocE :: Either (Either a b) c -> Either a (Either b c)
      assocE (Left (Left a)) = Left a
      assocE (Left (Right b)) = Right (Left b)
      assocE (Right c) = Right (Right c)
      unassocE :: Either a (Either b c) -> Either (Either a b) c
      unassocE (Left a) = Left (Left a)
      unassocE (Right (Left b) = Left (Right b)
      unassocE (Right (Right c)) = Right c)

Instances

Cochoice (->) Source # |
Methods unleft :: (Either a d -> Either b d) -> a -> b Source # unright :: (Either d a -> Either d b) -> a -> b Source #
Applicative f => Cochoice (Costar f) Source # |
Methods unleft :: Costar f (Either a d) (Either b d) -> Costar f a b Source # unright :: Costar f (Either d a) (Either d b) -> Costar f a b Source #
Traversable f => Cochoice (Star f) Source # |
Methods unleft :: Star f (Either a d) (Either b d) -> Star f a b Source # unright :: Star f (Either d a) (Either d b) -> Star f a b Source #
Cochoice (CopastroSum p) Source # |
Methods unleft :: CopastroSum p (Either a d) (Either b d) -> CopastroSum p a b Source # unright :: CopastroSum p (Either d a) (Either d b) -> CopastroSum p a b Source #
Cochoice (CotambaraSum p) Source # |
Methods unleft :: CotambaraSum p (Either a d) (Either b d) -> CotambaraSum p a b Source # unright :: CotambaraSum p (Either d a) (Either d b) -> CotambaraSum p a b Source #
Cochoice p => Cochoice (Coyoneda p) Source # |
Methods unleft :: Coyoneda p (Either a d) (Either b d) -> Coyoneda p a b Source # unright :: Coyoneda p (Either d a) (Either d b) -> Coyoneda p a b Source #
Cochoice p => Cochoice (Yoneda p) Source # |
Methods unleft :: Yoneda p (Either a d) (Either b d) -> Yoneda p a b Source # unright :: Yoneda p (Either d a) (Either d b) -> Yoneda p a b Source #
(Cochoice p, Cochoice q) => Cochoice (Product * * p q) Source # |
Methods unleft :: Product * * p q (Either a d) (Either b d) -> Product * * p q a b Source # unright :: Product * * p q (Either d a) (Either d b) -> Product * * p q a b Source #
(Functor f, Cochoice p) => Cochoice (Tannen * * * f p) Source # |
Methods unleft :: Tannen * * * f p (Either a d) (Either b d) -> Tannen * * * f p a b Source # unright :: Tannen * * * f p (Either d a) (Either d b) -> Tannen * * * f p a b Source #

data CotambaraSum q a b where Source #

`CotambaraSum` cofreely constructs costrength with respect to `Either` (aka `Choice`)

Constructors

CotambaraSum :: Cochoice r => (r :-> q) -> r a b -> CotambaraSum q a b |

Instances

ProfunctorComonad CotambaraSum Source # |
Methods proextract :: Profunctor p => CotambaraSum p :-> p Source # produplicate :: Profunctor p => CotambaraSum p :-> CotambaraSum (CotambaraSum p) Source #
ProfunctorFunctor CotambaraSum Source # |
Methods promap :: Profunctor p => (p :-> q) -> CotambaraSum p :-> CotambaraSum q Source #
ProfunctorAdjunction CopastroSum CotambaraSum Source # |
Methods unit :: Profunctor p => p :-> CotambaraSum (CopastroSum p) Source # counit :: Profunctor p => CopastroSum (CotambaraSum p) :-> p Source #
Profunctor (CotambaraSum p) Source # |

Methods

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

lmap :: (a -> b) -> CotambaraSum p b c -> CotambaraSum p a c Source #

rmap :: (b -> c) -> CotambaraSum p a b -> CotambaraSum p a c Source #

(#.) :: Coercible * c b => (b -> c) -> CotambaraSum p a b -> CotambaraSum p a c Source #

(.#) :: Coercible * b a => CotambaraSum p b c -> (a -> b) -> CotambaraSum p a c Source #

Cochoice (CotambaraSum p) Source # |
Methods unleft :: CotambaraSum p (Either a d) (Either b d) -> CotambaraSum p a b Source # unright :: CotambaraSum p (Either d a) (Either d b) -> CotambaraSum p a b Source #
Functor (CotambaraSum p a) Source # |
Methods fmap :: (a -> b) -> CotambaraSum p a a -> CotambaraSum p a b # (<$) :: a -> CotambaraSum p a b -> CotambaraSum p a a #

cotambaraSum :: Cochoice p => (p :-> q) -> p :-> CotambaraSum q Source #

    cotambaraSum . uncotambaraSum ≡ id
    uncotambaraSum . cotambaraSum ≡ id

uncotambaraSum :: Profunctor q => (p :-> CotambaraSum q) -> p :-> q Source #

    cotambaraSum . uncotambaraSum ≡ id
    uncotambaraSum . cotambaraSum ≡ id

newtype CopastroSum p a b Source #

CopastroSum -| CotambaraSum

`CopastroSum` freely constructs costrength with respect to `Either` (aka `Choice`)

Constructors

CopastroSum |

Fields

- runCopastroSum :: forall r. Cochoice r => (forall x y. p x y -> r x y) -> r a b

Instances

ProfunctorMonad CopastroSum Source # |
Methods proreturn :: Profunctor p => p :-> CopastroSum p Source # projoin :: Profunctor p => CopastroSum (CopastroSum p) :-> CopastroSum p Source #
ProfunctorFunctor CopastroSum Source # |
Methods promap :: Profunctor p => (p :-> q) -> CopastroSum p :-> CopastroSum q Source #
ProfunctorAdjunction CopastroSum CotambaraSum Source # |
Methods unit :: Profunctor p => p :-> CotambaraSum (CopastroSum p) Source # counit :: Profunctor p => CopastroSum (CotambaraSum p) :-> p Source #
Profunctor (CopastroSum p) Source # |
Methods dimap :: (a -> b) -> (c -> d) -> CopastroSum p b c -> CopastroSum p a d Source # lmap :: (a -> b) -> CopastroSum p b c -> CopastroSum p a c Source # rmap :: (b -> c) -> CopastroSum p a b -> CopastroSum p a c Source # (#.) :: Coercible * c b => (b -> c) -> CopastroSum p a b -> CopastroSum p a c Source # (.#) :: Coercible * b a => CopastroSum p b c -> (a -> b) -> CopastroSum p a c Source #
Cochoice (CopastroSum p) Source # |
Methods unleft :: CopastroSum p (Either a d) (Either b d) -> CopastroSum p a b Source # unright :: CopastroSum p (Either d a) (Either d b) -> CopastroSum p a b Source #