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

Modulegeneric-lens-2.2.2.0Haskell2010

Data.Generics.Labels

Provides an (orphan) IsLabel instance for field lenses and constructor prisms. Use at your own risk.

  • 2 types
  • 2 classes

Orphan IsLabel Instance

4 declarations

An instance for creating lenses and prisms with #identifiers from the OverloadedLabels extension. Note that since overloaded labels did not support symbols starting with capital letters, all prisms (which come from constructor names, which are capitalized) must be prefixed with an underscore (e.g. #_ConstructorName) when you use a GHC older than 9.6.

Morally:

instance (HasField name s t a b) => IsLabel name (Lens s t a b) where ...

and

instance (AsConstructor name s t a b) => IsLabel name (Prism s t a b) where ...

Remember:

type Lens = forall f. Functor f => (a -> f b) -> s -> f t

type Prism s t a b = forall p f. (Choice p, Applicative f) => p a (f b) -> p s (f t)

The orphan instance is unavoidable if we want to work with lenses-as-functions (as opposed to a ReifiedLens-like newtype).

classclass Field (name :: k) s t a b | s name -> a, t name -> b, s name b -> t, t name a -> s where
#

Field is morally the same as HasField, but it is constructed from an incoherent combination of HasField and HasField'. In this way, it can be seamlessly used in the IsLabel instance even when dealing with data types that don't have Field instances (like data instances).

Methods

Instances2Field
  • HasField name s t a b => Field name s t a bDefined in generic-lens-2.2.2.0 · Data.Generics.Labels
  • HasField' name s a => Field name s s a aDefined in generic-lens-2.2.2.0 · Data.Generics.Labels
classclass Constructor (name :: k) s t a b | name s -> a, name t -> b where
#

Constructor is morally the same as AsConstructor, but it is constructed from an incoherent combination of AsConstructor and AsConstructor'. In this way, it can be seamlessly used in the IsLabel instance even when dealing with data types that don't have Constructor instances (like data instances).

Methods

Instances2Constructor

Orphan instances

1 instance
  • (labelType ~ ClassifyLabel name, IsLabelHelper labelType name p f s t a b, pafb ~ p a (f b), psft ~ p s (f t)) => IsLabel name (pafb -> psft)