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.Positions

Derive positional product type getters and setters generically.

  • 4 classes
  • 2 values

Lenses

6 declarations

Running example:

Example9 expressions
:set -XTypeApplications:set -XDataKinds:set -XDeriveGeneric:set -XGADTs:set -XFlexibleContextsimport GHC.Generics:m +Data.Generics.Internal.VL.Lens:m +Data.Function:{data Human = Human  { name    :: String  , age     :: Int  , address :: String  }  deriving (Generic, Show)human :: Humanhuman = Human "Tunyasz" 50 "London":}
classclass HasPosition (i :: Nat) s t a b | s i -> a, t i -> b, s i b -> t, t i a -> s where
#

Records that have a field at a given position.

Methods

  • position :: Lens s t a b

    A lens that focuses on a field at a given position. Compatible with the lens package's Control.Lens.Lens type.

    Example2 expressions
    human ^. position @1"Tunyasz"human & position @3 .~ "Berlin"Human {name = "Tunyasz", age = 50, address = "Berlin"}
    Type errors
    Example1 expression
    human & position @4 .~ "Berlin"...... The type Human does not contain a field at position 4...
Instances2HasPosition
  • (Context i s t a b, HasPosition0 i s t a b) => HasPosition i s t a bDefined in generic-lens-2.2.2.0 · Data.Generics.Product.Positions
  • HasPosition f (Void1 a) (Void1 b) a bDefined in generic-lens-2.2.2.0 · Data.Generics.Product.Positions

    Uncluttering type signatures (see Void)

    Example1 expression
    :t +d positionposition  :: (HasPosition i s t a b, Functor f) => (a -> f b) -> s -> f t
classclass HasPosition0 (i :: Nat) s t a b where
#

Records that have a field at a given position.

This class gives the minimal constraints needed to define this lens. For common uses, see HasPosition.

Methods

Instances1HasPosition0
  • Context0 i s t a b => HasPosition0 i s t a bDefined in generic-lens-2.2.2.0 · Data.Generics.Product.Positions
valuesetPosition :: HasPosition' i s a => a -> s -> s
#
Example1 expression
setPosition @2 60 humanHuman {name = "Tunyasz", age = 60, address = "London"}