| Portability | portable |
|---|---|
| Stability | provisional |
| Maintainer | Edward Kmett <ekmett@gmail.com> |
| Safe Haskell | Trustworthy |
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 => Lenticular p where
- lenticular :: p a b -> p a (a, b)
- class Profunctor p => Prismatic p where
- newtype UpStar f d c = UpStar {
- runUpStar :: d -> f c
- newtype DownStar f d c = DownStar {
- runDownStar :: f d -> c
- newtype WrappedArrow p a b = WrapArrow {
- unwrapArrow :: p a b
Profunctors
class Profunctor p whereSource
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 dSource
Instances
| Profunctor (->) | |
| Monad m => Profunctor (Kleisli m) | |
| Functor w => Profunctor (Cokleisli w) | |
| Profunctor (Tagged *) | |
| Arrow p => Profunctor (WrappedArrow p) | |
| Functor f => Profunctor (DownStar f) | |
| Functor f => Profunctor (UpStar f) |
Profunctorial Strength
class Profunctor p => Lenticular p whereSource
Methods
lenticular :: p a b -> p a (a, b)Source
Instances
| Lenticular (->) | |
| (Profunctor (Kleisli m), Monad m) => Lenticular (Kleisli m) | |
| (Profunctor (WrappedArrow p), Arrow p) => Lenticular (WrappedArrow p) | |
| (Profunctor (UpStar m), Functor m) => Lenticular (UpStar m) |
class Profunctor p => Prismatic p whereSource
The generalization of DownStar of a "Costrong" Functor
Note: Here we use Traversable as an approximate costrength.
Instances
| Prismatic (->) | |
| (Profunctor (Kleisli m), Monad m) => Prismatic (Kleisli m) | |
| (Profunctor (Cokleisli w), Traversable w) => Prismatic (Cokleisli w) |
|
| Prismatic (Tagged *) | |
| (Profunctor (WrappedArrow p), ArrowChoice p) => Prismatic (WrappedArrow p) | |
| (Profunctor (DownStar w), Traversable w) => Prismatic (DownStar w) |
|
Common Profunctors
Lift a Functor into a Profunctor (forwards)
Instances
| Functor f => Profunctor (UpStar f) | |
| (Profunctor (UpStar m), Functor m) => Lenticular (UpStar m) | |
| Functor f => Functor (UpStar f a) |
Lift a Functor into a Profunctor (backwards)
Constructors
| DownStar | |
Fields
| |
Instances
| Functor f => Profunctor (DownStar f) | |
| (Profunctor (DownStar w), Traversable w) => Prismatic (DownStar w) |
|
| Functor (DownStar f a) |
newtype WrappedArrow p a b Source
Wrap an arrow for use as a Profunctor
Constructors
| WrapArrow | |
Fields
| |
Instances
| (Category (WrappedArrow p), Arrow p) => Arrow (WrappedArrow p) | |
| (Arrow (WrappedArrow p), ArrowZero p) => ArrowZero (WrappedArrow p) | |
| (Arrow (WrappedArrow p), ArrowChoice p) => ArrowChoice (WrappedArrow p) | |
| (Arrow (WrappedArrow p), ArrowApply p) => ArrowApply (WrappedArrow p) | |
| (Arrow (WrappedArrow p), ArrowLoop p) => ArrowLoop (WrappedArrow p) | |
| Category p => Category (WrappedArrow p) | |
| Arrow p => Profunctor (WrappedArrow p) | |
| (Profunctor (WrappedArrow p), ArrowChoice p) => Prismatic (WrappedArrow p) | |
| (Profunctor (WrappedArrow p), Arrow p) => Lenticular (WrappedArrow p) |