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

Modulegeneric-optics-2.2.1.0Haskell2010

Data.Generics.Product.Typed

Derive lenses of a given type in a product.

  • 1 class

Lenses

1 declaration

Running example:

Example6 expressions
:set -XTypeApplications:set -XDataKinds:set -XDeriveGenericimport GHC.Genericsimport Optics.Core:{data Human  = Human    { name    :: String    , age     :: Int    , address :: String    , tall    :: Bool    }  | HumanNoTall    { name    :: String    , age     :: Int    , address :: String    }  deriving (Generic, Show)human :: Humanhuman = Human "Tunyasz" 50 "London" False:}
classclass HasType a s where
#

Records that have a field with a unique type.

Methods

  • typed :: Lens s s a a

    A lens that focuses on a field with a unique type in its parent type.

    Example1 expression
    human ^. typed @Int50
    Type errors
    Example1 expression
    human ^. typed @String......... The type Human contains multiple values of type [Char].... The choice of value is thus ambiguous. The offending constructors are:... Human... HumanNoTall...
    Example1 expression
    human ^. typed @Bool......... Not all constructors of the type Human contain a field of type Bool.... The offending constructors are:... HumanNoTall...
  • getTyped :: s -> a

    Get field at type.

  • setTyped :: a -> s -> s

    Set field at type.

Instances3HasType
  • Context a s => HasType a sDefined in generic-optics-2.2.1.0 · Data.Generics.Product.Typed
  • HasType a VoidDefined in generic-optics-2.2.1.0 · Data.Generics.Product.Typed

    See Note [Uncluttering type signatures] >>> :t typed typed :: HasType a s => Lens s s a a

    Note that this might not longer be needed given the above 'HasType a a' instance.

  • HasType a aDefined in generic-optics-2.2.1.0 · Data.Generics.Product.Typed