| Copyright | (C) 2011-2015 Edward Kmett |
|---|---|
| License | BSD-style (see the file LICENSE) |
| Maintainer | Edward Kmett <ekmett@gmail.com> |
| Stability | provisional |
| Portability | portable |
| Safe Haskell | Safe |
| Language | Haskell2010 |
Data.Profunctor
Description
For a good explanation of profunctors in Haskell see Dan Piponi's article:
http://blog.sigfpe.com/2011/07/profunctors-in-haskell.html
For more information on strength and costrength, see:
http://comonad.com/reader/2008/deriving-strength-from-laziness/
- class Profunctor p where
- class Profunctor p => Strong p where
- uncurry' :: Strong p => p a (b -> c) -> p (a, b) c
- class Profunctor p => Choice p where
- class Profunctor p => Closed p where
- curry' :: Closed p => p (a, b) c -> p a (b -> c)
- class (Traversing p, Closed p) => Mapping p where
- class Profunctor p => Costrong p where
- class Profunctor p => Cochoice p where
- newtype Star f d c = Star {
- runStar :: d -> f c
- newtype Costar f d c = Costar {
- runCostar :: f d -> c
- newtype WrappedArrow p a b = WrapArrow {
- unwrapArrow :: p a b
- newtype Forget r a b = Forget {
- runForget :: a -> r
- type (:->) p q = forall a b. p a b -> q a b
Profunctors
class Profunctor p where Source #
Formally, the class Profunctor represents a profunctor
from Hask -> Hask.
Intuitively it is a bifunctor where the first argument is contravariant and the second argument is covariant.
You can define a Profunctor by either defining dimap or by defining both
lmap and rmap.
If you supply dimap, you should ensure that:
dimapidid≡id
If you supply lmap and rmap, ensure:
lmapid≡idrmapid≡id
If you supply both, you should also ensure:
dimapf g ≡lmapf.rmapg
These ensure by parametricity:
dimap(f.g) (h.i) ≡dimapg h.dimapf ilmap(f.g) ≡lmapg.lmapfrmap(f.g) ≡rmapf.rmapg
Methods
dimap :: (a -> b) -> (c -> d) -> p b c -> p a d Source #
Instances
Profunctorial Strength
class Profunctor p => Strong p where Source #
Generalizing Star of a strong Functor
Note: Every Functor in Haskell is strong with respect to (,).
This describes profunctor strength with respect to the product structure of Hask.
http://www-kb.is.s.u-tokyo.ac.jp/~asada/papers/arrStrMnd.pdf
Methods
Instances
| Strong (->) Source # | |
| Monad m => Strong (Kleisli m) Source # | |
| Strong (Forget r) Source # | |
| Arrow p => Strong (WrappedArrow p) Source # | |
| Functor m => Strong (Star m) Source # | |
| Strong (Pastro p) Source # | |
| Profunctor p => Strong (Tambara p) Source # | |
| Strong p => Strong (Closure p) Source # | |
| Strong (FreeTraversing p) Source # | |
| Profunctor p => Strong (CofreeTraversing p) Source # | |
| Strong (FreeMapping p) Source # | |
| Profunctor p => Strong (CofreeMapping p) Source # | |
| Strong p => Strong (Coyoneda p) Source # | |
| Strong p => Strong (Yoneda p) Source # | |
| (Functor f, Strong p) => Strong (Cayley f p) Source # | |
| (Strong p, Strong q) => Strong (Procompose p q) Source # | |
| Contravariant f => Strong (Clown * * f) Source # | |
| (Strong p, Strong q) => Strong (Product * * p q) Source # | |
| (Functor f, Strong p) => Strong (Tannen * * * f p) Source # | |
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.
Methods
left' :: p a b -> p (Either a c) (Either b c) Source #
Laws:
left'≡dimapswapE swapE.right'where swapE ::Eithera b ->Eitherb a swapE =eitherRightLeftrmapLeft≡lmapLeft.left'lmap(rightf).left'≡rmap(rightf).left'left'.left'≡dimapassocE unassocE.left'where assocE ::Either(Eithera b) c ->Eithera (Eitherb c) assocE (Left(Lefta)) =Lefta assocE (Left(Rightb)) =Right(Leftb) assocE (Rightc) =Right(Rightc) unassocE ::Eithera (Eitherb c) ->Either(Eithera b) c unassocE (Lefta) =Left(Lefta) unassocE (Right(Leftb) =Left(Rightb) unassocE (Right(Rightc)) =Rightc)
right' :: p a b -> p (Either c a) (Either c b) Source #
Laws:
right'≡dimapswapE swapE.left'where swapE ::Eithera b ->Eitherb a swapE =eitherRightLeftrmapRight≡lmapRight.right'lmap(leftf).right'≡rmap(leftf).right'right'.right'≡dimapunassocE assocE.right'where assocE ::Either(Eithera b) c ->Eithera (Eitherb c) assocE (Left(Lefta)) =Lefta assocE (Left(Rightb)) =Right(Leftb) assocE (Rightc) =Right(Rightc) unassocE ::Eithera (Eitherb c) ->Either(Eithera b) c unassocE (Lefta) =Left(Lefta) unassocE (Right(Leftb) =Left(Rightb) unassocE (Right(Rightc)) =Rightc)
Instances
| Choice (->) Source # | |
| Monad m => Choice (Kleisli m) Source # | |
| Comonad w => Choice (Cokleisli w) Source # |
|
| Choice (Tagged *) Source # | |
| Monoid r => Choice (Forget r) Source # | |
| ArrowChoice p => Choice (WrappedArrow p) Source # | |
| Traversable w => Choice (Costar w) Source # | |
| Applicative f => Choice (Star f) Source # | |
| Choice p => Choice (Tambara p) Source # | |
| Choice (PastroSum p) Source # | |
| Profunctor p => Choice (TambaraSum p) Source # | |
| Choice (FreeTraversing p) Source # | |
| Profunctor p => Choice (CofreeTraversing p) Source # | |
| Choice (FreeMapping p) Source # | |
| Profunctor p => Choice (CofreeMapping p) Source # | |
| Choice p => Choice (Coyoneda p) Source # | |
| Choice p => Choice (Yoneda p) Source # | |
| (Functor f, Choice p) => Choice (Cayley f p) Source # | |
| (Choice p, Choice q) => Choice (Procompose p q) Source # | |
| Functor f => Choice (Joker * * f) Source # | |
| (Choice p, Choice q) => Choice (Product * * p q) Source # | |
| (Functor f, Choice p) => Choice (Tannen * * * f p) Source # | |
Closed
class Profunctor p => Closed p where Source #
A strong profunctor allows the monoidal structure to pass through.
A closed profunctor allows the closed structure to pass through.
Minimal complete definition
Methods
Instances
| Closed (->) Source # | |
| (Distributive f, Monad f) => Closed (Kleisli f) Source # | |
| Functor f => Closed (Cokleisli f) Source # | |
| Closed (Tagged *) Source # | |
| Functor f => Closed (Costar f) Source # | |
| Distributive f => Closed (Star f) Source # | |
| Closed (Environment p) Source # | |
| Profunctor p => Closed (Closure p) Source # | |
| Closed (FreeMapping p) Source # | |
| Profunctor p => Closed (CofreeMapping p) Source # | |
| Closed p => Closed (Coyoneda p) Source # | |
| Closed p => Closed (Yoneda p) Source # | |
| (Closed p, Closed q) => Closed (Procompose p q) Source # | |
| (Closed p, Closed q) => Closed (Product * * p q) Source # | |
| (Functor f, Closed p) => Closed (Tannen * * * f p) Source # | |
class (Traversing p, Closed p) => Mapping p where Source #
Minimal complete definition
Methods
Instances
| Mapping (->) Source # | |
| (Monad m, Distributive m) => Mapping (Kleisli m) Source # | |
| (Applicative m, Distributive m) => Mapping (Star m) Source # | |
| Mapping (FreeMapping p) Source # | |
| Profunctor p => Mapping (CofreeMapping p) Source # | |
| Mapping p => Mapping (Coyoneda p) Source # | |
| Mapping p => Mapping (Yoneda p) Source # | |
| (Mapping p, Mapping q) => Mapping (Procompose p q) Source # | |
Profunctorial Costrength
class Profunctor p => Costrong p where Source #
Methods
Instances
| Costrong (->) Source # | |
| MonadFix m => Costrong (Kleisli m) Source # | |
| Functor f => Costrong (Cokleisli f) Source # | |
| Costrong (Tagged *) Source # | |
| ArrowLoop p => Costrong (WrappedArrow p) Source # | |
| Functor f => Costrong (Costar f) Source # | |
| Costrong (Copastro p) Source # | |
| Costrong (Cotambara p) Source # | |
| Costrong p => Costrong (Coyoneda p) Source # | |
| Costrong p => Costrong (Yoneda p) Source # | |
| (Corepresentable p, Corepresentable q) => Costrong (Procompose p q) Source # | |
| (Costrong p, Costrong q) => Costrong (Product * * p q) Source # | |
| (Functor f, Costrong p) => Costrong (Tannen * * * f p) Source # | |
class Profunctor p => Cochoice p where Source #
Methods
unleft :: p (Either a d) (Either b d) -> p a b Source #
Laws:
unleft≡unright.dimapswapE swapE where swapE ::Eithera b ->Eitherb a swapE =eitherRightLeftrmap(eitheridabsurd) ≡unleft.lmap(eitheridabsurd)unfirst.rmap(secondf) ≡unfirst.lmap(secondf)unleft.unleft≡unleft.dimapassocE unassocE where assocE ::Either(Eithera b) c ->Eithera (Eitherb c) assocE (Left(Lefta)) =Lefta assocE (Left(Rightb)) =Right(Leftb) assocE (Rightc) =Right(Rightc) unassocE ::Eithera (Eitherb c) ->Either(Eithera b) c unassocE (Lefta) =Left(Lefta) unassocE (Right(Leftb) =Left(Rightb) unassocE (Right(Rightc)) =Rightc)
unright :: p (Either d a) (Either d b) -> p a b Source #
Laws:
unright≡unleft.dimapswapE swapE where swapE ::Eithera b ->Eitherb a swapE =eitherRightLeftrmap(eitherabsurdid) ≡unright.lmap(eitherabsurdid)unsecond.rmap(firstf) ≡unsecond.lmap(firstf)unright.unright≡unright.dimapunassocE assocE where assocE ::Either(Eithera b) c ->Eithera (Eitherb c) assocE (Left(Lefta)) =Lefta assocE (Left(Rightb)) =Right(Leftb) assocE (Rightc) =Right(Rightc) unassocE ::Eithera (Eitherb c) ->Either(Eithera b) c unassocE (Lefta) =Left(Lefta) unassocE (Right(Leftb) =Left(Rightb) unassocE (Right(Rightc)) =Rightc)
Instances
| Cochoice (->) Source # | |
| Applicative f => Cochoice (Costar f) Source # | |
| Traversable f => Cochoice (Star f) Source # | |
| Cochoice (CopastroSum p) Source # | |
| Cochoice (CotambaraSum p) Source # | |
| Cochoice p => Cochoice (Coyoneda p) Source # | |
| Cochoice p => Cochoice (Yoneda p) Source # | |
| (Cochoice p, Cochoice q) => Cochoice (Product * * p q) Source # | |
| (Functor f, Cochoice p) => Cochoice (Tannen * * * f p) Source # | |
Common Profunctors
Lift a Functor into a Profunctor (forwards).
Instances
| Functor f => Profunctor (Star f) Source # | |
| Functor m => Strong (Star m) Source # | |
| Traversable f => Cochoice (Star f) Source # | |
| Applicative f => Choice (Star f) Source # | |
| Distributive f => Closed (Star f) Source # | |
| Applicative m => Traversing (Star m) Source # | |
| (Applicative m, Distributive m) => Mapping (Star m) Source # | |
| Functor f => Representable (Star f) Source # | |
| Functor f => Sieve (Star f) f Source # | |
| Monad f => Category * (Star f) Source # | |
| Monad f => Monad (Star f a) Source # | |
| Functor f => Functor (Star f a) Source # | |
| Applicative f => Applicative (Star f a) Source # | |
| Alternative f => Alternative (Star f a) Source # | |
| MonadPlus f => MonadPlus (Star f a) Source # | |
| Distributive f => Distributive (Star f a) Source # | |
| type Rep (Star f) Source # | |
Lift a Functor into a Profunctor (backwards).
Instances
| Functor f => Profunctor (Costar f) Source # | |
| Functor f => Costrong (Costar f) Source # | |
| Applicative f => Cochoice (Costar f) Source # | |
| Traversable w => Choice (Costar w) Source # | |
| Functor f => Closed (Costar f) Source # | |
| Functor f => Corepresentable (Costar f) Source # | |
| Functor f => Cosieve (Costar f) f Source # | |
| Monad (Costar f a) Source # | |
| Functor (Costar f a) Source # | |
| Applicative (Costar f a) Source # | |
| Distributive (Costar f d) Source # | |
| type Corep (Costar f) Source # | |
newtype WrappedArrow p a b Source #
Wrap an arrow for use as a Profunctor.
Constructors
| WrapArrow | |
Fields
| |
Instances
| Arrow p => Arrow (WrappedArrow p) Source # | |
| ArrowZero p => ArrowZero (WrappedArrow p) Source # | |
| ArrowChoice p => ArrowChoice (WrappedArrow p) Source # | |
| ArrowApply p => ArrowApply (WrappedArrow p) Source # | |
| ArrowLoop p => ArrowLoop (WrappedArrow p) Source # | |
| Arrow p => Profunctor (WrappedArrow p) Source # | |
| ArrowLoop p => Costrong (WrappedArrow p) Source # | |
| Arrow p => Strong (WrappedArrow p) Source # | |
| ArrowChoice p => Choice (WrappedArrow p) Source # | |
| Category * p => Category * (WrappedArrow p) Source # | |
Instances
| Profunctor (Forget r) Source # | |
| Strong (Forget r) Source # | |
| Monoid r => Choice (Forget r) Source # | |
| Monoid m => Traversing (Forget m) Source # | |
| Representable (Forget r) Source # | |
| Sieve (Forget r) (Const * r) Source # | |
| Functor (Forget r a) Source # | |
| Foldable (Forget r a) Source # | |
| Traversable (Forget r a) Source # | |
| type Rep (Forget r) Source # | |