Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module provides profunctor classes and instances.
Please import this module qualified.
Some of the definitions in this module are heavily connected to and
motivated by linear optics. Please see Control.Optics.Linear
and other
optics modules for motivations for the definitions provided here.
Connections to Linear Optics
Strong
andWandering
are classes drawn from this paperExchange
andMarket
are ways of encoding isomorphisms and prisms
Synopsis
- class Profunctor (arr :: Type -> Type -> Type) where
- class (SymmetricMonoidal m u, Profunctor arr) => Monoidal m u arr where
- class (SymmetricMonoidal m u, Profunctor arr) => Strong m u arr where
- class (Strong (,) () arr, Strong Either Void arr) => Wandering arr where
- wander :: forall s t a b. (forall f. Applicative f => (a %1 -> f b) -> s %1 -> f t) -> (a `arr` b) -> s `arr` t
- data Exchange a b s t = Exchange (s %1 -> a) (b %1 -> t)
- data Market a b s t = Market (b %1 -> t) (s %1 -> Either t a)
- runMarket :: Market a b s t %1 -> (b %1 -> t, s %1 -> Either t a)
Documentation
class Profunctor (arr :: Type -> Type -> Type) where Source #
A Profunctor can be thought of as a computation that involves taking
a
(s) as input and returning b
(s). These computations compose with
(linear) functions. Profunctors generalize the function arrow ->
.
Hence, think of a value of type x
for profunctor arr
yarr
to be
something like a function from x
to y
.
Laws:
lmap id = id lmap (f . g) = lmap f . lmap g rmap id = id rmap (f . g) = rmap f . rmap g
dimap :: (s %1 -> a) -> (b %1 -> t) -> (a `arr` b) -> s `arr` t Source #
Instances
Functor f => Profunctor (Kleisli f) Source # | |
Functor f => Profunctor (CoKleisli f) Source # | |
Functor f => Profunctor (Kleisli f) Source # | |
Profunctor (Exchange a b) Source # | |
Profunctor (Market a b) Source # | |
Profunctor (->) Source # | |
Profunctor (FUN 'One :: TYPE LiftedRep -> TYPE LiftedRep -> Type) Source # | |
class (SymmetricMonoidal m u, Profunctor arr) => Monoidal m u arr where Source #
A (Monoidal m u arr)
is a profunctor arr
that can be sequenced
with the bifunctor m
. In rough terms, you can combine two function-like
things to one function-like thing that holds both input and output types
with the bifunctor m
.
Instances
Functor f => Monoidal Either Void (Kleisli f) Source # | |
Functor f => Monoidal Either Void (Kleisli f) Source # | |
Applicative f => Monoidal (,) () (Kleisli f) Source # | |
Applicative f => Monoidal (,) () (Kleisli f) Source # | |
Monoidal Either Void (->) Source # | |
Monoidal (,) () (->) Source # | |
Monoidal Either Void (FUN 'One :: TYPE LiftedRep -> TYPE LiftedRep -> Type) Source # | |
Monoidal (,) () (FUN 'One :: TYPE LiftedRep -> TYPE LiftedRep -> Type) Source # | |
class (SymmetricMonoidal m u, Profunctor arr) => Strong m u arr where Source #
A (Strong m u arr)
instance means that the function-like thing
of type a
can be extended to pass along a value of type arr
bc
as a constant via the bifunctor of type m
.
This typeclass is used primarily to generalize common patterns and instances that are defined when defining optics. The two uses below are used in defining lenses and prisms respectively in Control.Optics.Linear.Internal:
If m
is the tuple
type constructor (,)
then we can create a function-like thing
of type (a,c)
passing along arr
(b,c)c
as a constant.
If m
is Either
then we can create a function-like thing of type
Either a c
that either does the original function
or behaves like the constant function.arr
Either b c
Instances
Applicative f => Strong Either Void (Kleisli f) Source # | |
Strong Either Void (CoKleisli (Const x :: Type -> Type)) Source # | |
Applicative f => Strong Either Void (Kleisli f) Source # | |
Functor f => Strong (,) () (Kleisli f) Source # | |
Functor f => Strong (,) () (Kleisli f) Source # | |
Strong Either Void (Market a b) Source # | |
Strong Either Void (->) Source # | |
Strong (,) () (->) Source # | |
Strong Either Void (FUN 'One :: TYPE LiftedRep -> TYPE LiftedRep -> Type) Source # | |
Strong (,) () (FUN 'One :: TYPE LiftedRep -> TYPE LiftedRep -> Type) Source # | |
class (Strong (,) () arr, Strong Either Void arr) => Wandering arr where Source #
A Wandering arr
instance means that there is a wander
function
which is the traversable generalization of the classic lens function:
forall f. Functor f => (a -> f b) -> (s -> f t)
in our notation:
forall arr. (HasKleisliFunctor arr) => (a `arr` b) -> (s `arr` t)
wander
specializes the Functor
constraint to a control applicative:
forall f. Applicative f => (a -> f b) -> (s -> f t) forall arr. (HasKleisliApplicative arr) => (a `arr` b) -> (s `arr` t)
where HasKleisliFunctor
or HasKleisliApplicative
are some constraints
which allow for the arr
to be Kleisli f
for control functors
or applicatives f
.
wander :: forall s t a b. (forall f. Applicative f => (a %1 -> f b) -> s %1 -> f t) -> (a `arr` b) -> s `arr` t Source #
Equivalently but less efficient in general:
wander :: Data.Traversable f => a `arr` b -> f a `arr` f b
data Exchange a b s t Source #
An exchange is a pair of translation functions that encode an
isomorphism; an Exchange a b s t
is equivalent to a Iso a b s t
.
Exchange (s %1 -> a) (b %1 -> t) |