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
- newtype LinearArrow a b = LA (a %1 -> b)
- getLA :: LinearArrow a b %1 -> a %1 -> b
- 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
Profunctor LinearArrow Source # | |
Defined in Data.Profunctor.Linear dimap :: (s %1 -> a) -> (b %1 -> t) -> LinearArrow a b -> LinearArrow s t Source # lmap :: (s %1 -> a) -> LinearArrow a t -> LinearArrow s t Source # rmap :: (b %1 -> t) -> LinearArrow s b -> LinearArrow s t Source # | |
Functor f => Profunctor (Kleisli f) Source # | |
Functor f => Profunctor (CoKleisli f) Source # | |
Functor f => Profunctor (Kleisli f) Source # | |
Profunctor (->) Source # | |
Profunctor (Market a b) Source # | |
Profunctor (Exchange a b) 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
Monoidal Either Void LinearArrow Source # | |
Defined in Data.Profunctor.Linear (***) :: LinearArrow a b -> LinearArrow x y -> LinearArrow (Either a x) (Either b y) Source # | |
Monoidal (,) () LinearArrow Source # | |
Defined in Data.Profunctor.Linear (***) :: LinearArrow a b -> LinearArrow x y -> LinearArrow (a, x) (b, y) Source # unit :: LinearArrow () () Source # | |
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 # | |
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
Strong Either Void LinearArrow Source # | |
Defined in Data.Profunctor.Linear first :: LinearArrow a b -> LinearArrow (Either a c) (Either b c) Source # second :: LinearArrow b c -> LinearArrow (Either a b) (Either a c) Source # | |
Strong (,) () LinearArrow Source # | |
Defined in Data.Profunctor.Linear first :: LinearArrow a b -> LinearArrow (a, c) (b, c) Source # second :: LinearArrow b c -> LinearArrow (a, b) (a, c) Source # | |
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 (->) Source # | |
Strong Either Void (Market a b) Source # | |
Strong (,) () (->) 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
Instances
Wandering LinearArrow Source # | |
Defined in Data.Profunctor.Linear wander :: forall s t a b. (forall (f :: Type -> Type). Applicative f => (a %1 -> f b) -> s %1 -> f t) -> LinearArrow a b -> LinearArrow s t Source # | |
Applicative f => Wandering (Kleisli f) Source # | |
Defined in Data.Profunctor.Kleisli.Linear |
newtype LinearArrow a b Source #
This newtype is needed to implement Profunctor
instances of #->
.
LA (a %1 -> b) |
Instances
getLA :: LinearArrow a b %1 -> a %1 -> b Source #
Temporary deconstructor since inference doesn't get it right
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) |