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

Modulegeneric-lens-2.3.0.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
#

Types that contain another type, either by being a record with a field with that type, or by actually being that 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.3.0.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.3.0.0 · Data.Generics.Product.Typed

    Every type has itself.

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