profunctors-5.2: Profunctors

Copyright(C) 2011-2015 Edward Kmett,
LicenseBSD-style (see the file LICENSE)
MaintainerEdward Kmett <ekmett@gmail.com>
Stabilityprovisional
Portabilityportable
Safe HaskellTrustworthy
LanguageHaskell2010

Data.Profunctor

Contents

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/

Synopsis

Profunctors

class Profunctor p where

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:

dimap id idid

If you supply lmap and rmap, ensure:

lmap idid
rmap idid

If you supply both, you should also ensure:

dimap f g ≡ lmap f . rmap g

These ensure by parametricity:

dimap (f . g) (h . i) ≡ dimap g h . dimap f i
lmap (f . g) ≡ lmap g . lmap f
rmap (f . g) ≡ rmap f . rmap g

Minimal complete definition

dimap | lmap, rmap

Methods

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

Map over both arguments at the same time.

dimap f g ≡ lmap f . rmap g

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

Map the first argument contravariantly.

lmap f ≡ dimap f id

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

Map the second argument covariantly.

rmapdimap id

Profunctorial Strength

class Profunctor p => Strong p where

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

Minimal complete definition

first' | second'

Methods

first' :: p a b -> p (a, c) (b, c)

second' :: p a b -> p (c, a) (c, b)

uncurry' :: Strong p => p a (b -> c) -> p (a, b) c

class Profunctor p => Choice p where

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)

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

Instances

Choice (->) 
Monad m => Choice (Kleisli m) 
Comonad w => Choice (Cokleisli w)

extract approximates costrength

Choice (Tagged *) 
Monoid r => Choice (Forget r) 
ArrowChoice p => Choice (WrappedArrow p) 
Traversable w => Choice (Costar w) 
Applicative f => Choice (Star f) 
Choice p => Choice (Tambara p) 
Choice (PastroSum p) 
Profunctor p => Choice (TambaraSum p) 
Choice (FreeTraversing p) 
Profunctor p => Choice (CofreeTraversing p) 
Choice (FreeMapping p) 
Profunctor p => Choice (CofreeMapping p) 
(Functor f, Choice p) => Choice (Cayley f p) 
(Choice p, Choice q) => Choice (Procompose p q) 
Functor f => Choice (Joker * * f) 
(Choice p, Choice q) => Choice (Product * * p q) 
(Functor f, Choice p) => Choice (Tannen * * * f p) 

Closed

class Profunctor p => Closed p where

A strong profunctor allows the monoidal structure to pass through.

A closed profunctor allows the closed structure to pass through.

Methods

closed :: p a b -> p (x -> a) (x -> b)

Instances

Closed (->) 
(Distributive f, Monad f) => Closed (Kleisli f) 
Functor f => Closed (Cokleisli f) 
Closed (Tagged *) 
Functor f => Closed (Costar f) 
Distributive f => Closed (Star f) 
Closed (Environment p) 
Profunctor p => Closed (Closure p) 
Closed (FreeMapping p) 
Profunctor p => Closed (CofreeMapping p) 
(Closed p, Closed q) => Closed (Procompose p q) 
(Closed p, Closed q) => Closed (Product * * p q) 
(Functor f, Closed p) => Closed (Tannen * * * f p) 

curry' :: Closed p => p (a, b) c -> p a (b -> c)

class (Traversing p, Closed p) => Mapping p where

Methods

map' :: Functor f => p a b -> p (f a) (f b)

Profunctorial Costrength

class Profunctor p => Costrong p where

Analogous to ArrowLoop, loop = unfirst

Minimal complete definition

unfirst | unsecond

Methods

unfirst :: p (a, d) (b, d) -> p a b

unsecond :: p (d, a) (d, b) -> p a b

class Profunctor p => Cochoice p where

Minimal complete definition

unleft | unright

Methods

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

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

Instances

Common Profunctors

newtype Star f d c

Lift a Functor into a Profunctor (forwards).

Constructors

Star 

Fields

runStar :: d -> f c
 

Instances

Functor f => Profunctor (Star f) 
Functor m => Strong (Star m) 
Distributive f => Closed (Star f) 
Traversable f => Cochoice (Star f) 
Applicative f => Choice (Star f) 
Applicative m => Traversing (Star m) 
(Applicative m, Distributive m) => Mapping (Star m) 
Functor f => Representable (Star f) 
Functor f => Sieve (Star f) f 
Monad f => Monad (Star f a) 
Functor f => Functor (Star f a) 
Applicative f => Applicative (Star f a) 
Alternative f => Alternative (Star f a) 
MonadPlus f => MonadPlus (Star f a) 
Distributive f => Distributive (Star f a) 
type Rep (Star f) = f 

newtype Costar f d c

Lift a Functor into a Profunctor (backwards).

Constructors

Costar 

Fields

runCostar :: f d -> c
 

Instances

newtype Forget r a b

Constructors

Forget 

Fields

runForget :: a -> r
 

Instances

type (:->) p q = forall a b. p a b -> q a b infixr 0