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

Derive positional product type getters and setters generically.

  • 4 classes
  • 2 values

Lenses

6 declarations

Running example:

Example8 expressions
:set -XTypeApplications:set -XDataKinds:set -XDeriveGeneric:set -XGADTs:set -XFlexibleContextsimport GHC.Genericsimport Optics.Core:{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.

    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-optics-2.2.1.0 · Data.Generics.Product.Positions
  • HasPosition f (Void1 a) (Void1 b) a bDefined in generic-optics-2.2.1.0 · Data.Generics.Product.Positions

    See Note [Uncluttering type signatures] >>> :t position position :: HasPosition i s t a b => Lens s t a b

classclass HasPosition' (i :: Nat) s a | s i -> a where
#

Records that have a field at a given position.

The difference between HasPosition and HasPosition_ is similar to the one between HasField and HasField_. See HasField_.

Methods

Instances1HasPosition'
  • Context' i s a => HasPosition' i s aDefined in generic-optics-2.2.1.0 · Data.Generics.Product.Positions
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-optics-2.2.1.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"}