HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleoptics-core-0.4.1.1Haskell2010

Optics.Internal.Optic

Core optic types and subtyping machinery.

This module contains the core Optic types, and the underlying machinery that we need in order to implement the subtyping between various different flavours of optics.

The composition operator for optics is also defined here.

This module is intended for internal use only, and may change without warning in subsequent releases.

  • 4 types
  • 5 values
newtypenewtype Optic (k :: OpticKind) (is :: IxList) s t a b
#

Wrapper newtype for the whole family of optics.

The first parameter k identifies the particular optic kind (e.g. A_Lens or A_Traversal).

The parameter is is a list of types available as indices. This will typically be NoIx for unindexed optics, or WithIx for optics with a single index. See the "Indexed optics" section of the overview documentation in the Optics module of the main optics package for more details.

The parameters s and t represent the "big" structure, whereas a and b represent the "small" structure.

Constructors

Instances1IsLabel
typetype Optic' (k :: OpticKind) (is :: IxList) s a = Optic k is s s a a
#

Common special case of Optic where source and target types are equal.

Here, we need only one "big" and one "small" type. For lenses, this means that in the restricted form we cannot do type-changing updates.

typetype Optic__ (p :: k -> k1 -> k2 -> Type) (i :: k) (j :: k) (s :: k1) (t :: k2) (a :: k1) (b :: k2) = p i a b -> p j s t
#

Optic internally as a profunctor transformation.

valuecastOptic
  1. :: Is srcKind destKind
  2. => Optic srcKind is s t a b
  3. -> Optic destKind is s t a b
#

Explicit cast from one optic flavour to another.

The resulting optic kind is given in the first type argument, so you can use TypeApplications to set it. For example

 castOptic @A_Lens o

turns o into a Lens.

This is the identity function, modulo some constraint jiggery-pokery.

value(%)
  1. :: (JoinKinds k l m, AppendIndices is js ks)
  2. => Optic k is s t u v
  3. -> Optic l js u v a b
  4. -> Optic m ks s t a b
#

Compose two optics of compatible flavours.

Returns an optic of the appropriate supertype. If either or both optics are indexed, the composition preserves all the indices.

value(%%)
  1. :: AppendIndices is js ks
  2. => Optic k is s t u v
  3. -> Optic k js u v a b
  4. -> Optic k ks s t a b
#

Compose two optics of the same flavour.

Normally you can simply use (%) instead, but this may be useful to help type inference if the type of one of the optics is otherwise under-constrained.

value(%&)
  1. :: Optic k is s t a b
  2. -> Optic k is s t a b -> Optic l js s' t' a' b'
  3. -> Optic l js s' t' a' b'
#

Flipped function application, specialised to optics and binding tightly.

Useful for post-composing optics transformations:

Example1 expression
toListOf (ifolded %& ifiltered (\i s -> length s <= i)) ["", "a","abc"]["","a"]

Re-exports

0 declarations