HORIZON HASKELLDocslts/ghc-10.0.xfc4e5982026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · fc4e598 · 2026-10-11

Moduleeither-n-0.1.0.0Haskell2010

Data.Lens.Injection.Generic

A prism to the nth constructor of any type with a Generic instance.

This is the default implementation of each of the InjectionN classes. The class GInjection is exported so that it can be named in constraints; the machinery behind it is in Data.Lens.Injection.Generic.Internal.

  • 1 class
  • 1 value
  • Packageeither-n-0.1.0.0
  • Exports2
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceGeneric.hs

Prism

1 declaration
valueinjection
  1. :: (Generic s, Generic t, GInjection n (Rep s) (Rep t) a b)
  2. => proxy n
  3. -> Prism s t a b
#

A prism to the nth constructor (counting from 0) of a type with a Generic instance, where n is given by a proxy, such as Proxy @0.

The focus of the prism depends on the fields of the constructor:

  • No fields: the focus is ().

  • One field: the focus is that field.

  • More than one field: the focus is any type with a single constructor that has the same fields, such as a tuple.

Example1 expression
T1 'x' ^? injection (Proxy @0)Just 'x'
Example1 expression
T2 ^? injection (Proxy @0)Nothing

Unlike the InjectionN classes, injection has no functional dependencies, so a type-changing use may need a type annotation.

Example1 expression
over (injection (Proxy @0)) show (T1 1) :: T StringT1 "1"
Example1 expression
(T2 :: T Char) ^? injection (Proxy @1)Just ()
Example1 expression
(T3 1 True :: T Char) ^? injection (Proxy @2) :: Maybe (Int, Bool)Just (1,True)
Example1 expression
injection (Proxy @2) # (1, True) :: T CharT3 1 True

Generic machinery

1 declaration
classclass GInjection (n :: Nat) (s :: Type -> Type) (t :: Type -> Type) a b where
#

A prism to the nth constructor of a generic representation.

Instances5GInjection