HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulelinear-base-0.4.0Haskell2010

Data.Profunctor.Linear

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

  • 2 types
  • 4 classes
  • 1 value
classclass Profunctor (arr :: Type -> Type -> Type) where
#

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 arr y for profunctor arr 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

Methods

  • dimap :: (s %1 -> a) -> (b %1 -> t) -> arr a b -> arr s t
  • lmap :: (s %1 -> a) -> arr a t -> arr s t
  • rmap :: (b %1 -> t) -> arr s b -> arr s t
Instances7Profunctor, …
classclass (SymmetricMonoidal m u, Profunctor arr) => Monoidal (m :: Type -> Type -> Type) u (arr :: Type -> Type -> Type) where
#

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.

Methods

  • (***) :: arr a b -> arr x y -> arr (m a x) (m b y)infixr 3
  • unit :: arr u u
Instances8Monoidal, …
classclass (SymmetricMonoidal m u, Profunctor arr) => Strong (m :: Type -> Type -> Type) u (arr :: Type -> Type -> Type) where
#

A (Strong m u arr) instance means that the function-like thing of type a arr b can be extended to pass along a value of type c 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) arr (b,c) passing along c as a constant.

If m is Either then we can create a function-like thing of type Either a c arr Either b c that either does the original function or behaves like the constant function.

Methods

  • first :: arr a b -> arr (m a c) (m b c)
  • second :: arr b c -> arr (m a b) (m a c)
Instances10Strong, …
classclass (Strong Tuple2 () arr, Strong Either Void arr) => Wandering (arr :: Type -> Type -> Type) where
#

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.

Methods

  • wander :: (forall (f :: Type -> Type). Applicative f => (a %1 -> f b) -> s %1 -> f t) -> arr a b -> arr s t

    Equivalently but less efficient in general:

    wander :: Data.Traversable f => a `arr` b -> f a `arr` f b
Instances2Wandering
datadata Exchange a b s t
#

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.

Constructors

Instances1Profunctor
datadata Market a b s t
#

A market is a pair of constructor and deconstructor functions that encode a prism; a Market a b s t is equivalent to a Prism a b s t.

Constructors

Instances2Strong, Profunctor