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-lens-2.2.2.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.Generics:m +Data.Generics.Internal.VL.Lens:{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. Compatible with the lens package's Control.Lens.Lens 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
  • HasType a VoidDefined in generic-lens-2.2.2.0 · Data.Generics.Product.Typed

    Uncluttering type signatures (see Void)

    Example1 expression
    :t +d typedtyped :: (HasType a s, Functor f) => (a -> f a) -> s -> f s

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

  • HasType a aDefined in generic-lens-2.2.2.0 · Data.Generics.Product.Typed
  • Context a s => HasType a sDefined in generic-lens-2.2.2.0 · Data.Generics.Product.Typed