HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleoptics-core-0.4.1.1Haskell2010

Data.Tuple.Optics

This module defines Lenses for the fields of tuple types. These are overloaded using the Field1 to Field9 typeclasses, so that _1 can be used as a Lens for the first field of a tuple with any number of fields (up to the maximum supported tuple size, which is currently 9). For example:

Example1 expression
view _1 ('a','b','c')'a'
Example1 expression
set _3 True ('a','b','c')('a','b',True)

If a datatype has a Generic instance, the corresponding FieldN instances can be defined using their default methods:

Example6 expressions
:set -XDeriveGenericimport GHC.Generics (Generic)data T a b = MkT a Int b deriving (Generic, Show)instance Field1 (T a c) (T b c) a binstance Field2 (T a b) (T a b) Int Intinstance Field3 (T c a) (T c b) a b
Example1 expression
set _3 'x' (MkT False 1 ())MkT False 1 'x'

For a generalization of this pattern see GPosition.

  • 9 classes
  • 9 values

Tuples

9 declarations
classclass Field1 s t a b | s -> a, t -> b, s b -> t, t a -> s where
#

Provides access to 1st field of a tuple.

Methods

  • _1 :: Lens s t a b

    Access the 1st field of a tuple (and possibly change its type).

    Example1 expression
    (1,2) ^. _11
    Example1 expression
    (1,2) & _1 .~ "hello"("hello",2)
    Example1 expression
    traverseOf _1 putStrLn ("hello","world")hello((),"world")

    This can also be used on larger tuples as well:

    Example1 expression
    (1,2,3,4,5) & _1 %~ (+41)(42,2,3,4,5)
Instances11Field1, …
  • Field1 (Identity a) (Identity b) a bDefined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field1 (a, b) (a', b) a a'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field1 (a, b, c) (a', b, c) a a'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field1 (a, b, c, d) (a', b, c, d) a a'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field1 (Product f g a) (Product f' g a) (f a) (f' a)Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field1 ((:*:) f g p) ((:*:) f' g p) (f p) (f' p)Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field1 (a, b, c, d, e) (a', b, c, d, e) a a'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field1 (a, b, c, d, e, f) (a', b, c, d, e, f) a a'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field1 (a, b, c, d, e, f, g) (a', b, c, d, e, f, g) a a'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field1 (a, b, c, d, e, f, g, h) (a', b, c, d, e, f, g, h) a a'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field1 (a, b, c, d, e, f, g, h, i) (a', b, c, d, e, f, g, h, i) a a'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
classclass Field2 s t a b | s -> a, t -> b, s b -> t, t a -> s where
#

Provides access to the 2nd field of a tuple.

Methods

  • _2 :: Lens s t a b

    Access the 2nd field of a tuple.

    Example1 expression
    _2 .~ "hello" $ (1,(),3,4)(1,"hello",3,4)
    Example1 expression
    (1,2,3,4) & _2 %~ (*3)(1,6,3,4)
    Example1 expression
    traverseOf _2 print (1,2)2(1,())
Instances10Field2, …
  • Field2 (a, b) (a, b') b b'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field2 (a, b, c) (a, b', c) b b'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field2 (a, b, c, d) (a, b', c, d) b b'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field2 (Product f g a) (Product f g' a) (g a) (g' a)Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field2 ((:*:) f g p) ((:*:) f g' p) (g p) (g' p)Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field2 (a, b, c, d, e) (a, b', c, d, e) b b'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field2 (a, b, c, d, e, f) (a, b', c, d, e, f) b b'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field2 (a, b, c, d, e, f, g) (a, b', c, d, e, f, g) b b'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field2 (a, b, c, d, e, f, g, h) (a, b', c, d, e, f, g, h) b b'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field2 (a, b, c, d, e, f, g, h, i) (a, b', c, d, e, f, g, h, i) b b'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
classclass Field3 s t a b | s -> a, t -> b, s b -> t, t a -> s where
#

Provides access to the 3rd field of a tuple.

Methods

  • _3 :: Lens s t a b

    Access the 3rd field of a tuple.

Instances7Field3, …
  • Field3 (a, b, c) (a, b, c') c c'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field3 (a, b, c, d) (a, b, c', d) c c'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field3 (a, b, c, d, e) (a, b, c', d, e) c c'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field3 (a, b, c, d, e, f) (a, b, c', d, e, f) c c'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field3 (a, b, c, d, e, f, g) (a, b, c', d, e, f, g) c c'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field3 (a, b, c, d, e, f, g, h) (a, b, c', d, e, f, g, h) c c'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field3 (a, b, c, d, e, f, g, h, i) (a, b, c', d, e, f, g, h, i) c c'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
classclass Field4 s t a b | s -> a, t -> b, s b -> t, t a -> s where
#

Provide access to the 4th field of a tuple.

Methods

  • _4 :: Lens s t a b

    Access the 4th field of a tuple.

Instances6Field4
  • Field4 (a, b, c, d) (a, b, c, d') d d'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field4 (a, b, c, d, e) (a, b, c, d', e) d d'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field4 (a, b, c, d, e, f) (a, b, c, d', e, f) d d'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field4 (a, b, c, d, e, f, g) (a, b, c, d', e, f, g) d d'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field4 (a, b, c, d, e, f, g, h) (a, b, c, d', e, f, g, h) d d'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field4 (a, b, c, d, e, f, g, h, i) (a, b, c, d', e, f, g, h, i) d d'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
classclass Field5 s t a b | s -> a, t -> b, s b -> t, t a -> s where
#

Provides access to the 5th field of a tuple.

Methods

  • _5 :: Lens s t a b

    Access the 5th field of a tuple.

Instances5Field5
  • Field5 (a, b, c, d, e) (a, b, c, d, e') e e'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field5 (a, b, c, d, e, f) (a, b, c, d, e', f) e e'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field5 (a, b, c, d, e, f, g) (a, b, c, d, e', f, g) e e'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field5 (a, b, c, d, e, f, g, h) (a, b, c, d, e', f, g, h) e e'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field5 (a, b, c, d, e, f, g, h, i) (a, b, c, d, e', f, g, h, i) e e'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
classclass Field6 s t a b | s -> a, t -> b, s b -> t, t a -> s where
#

Provides access to the 6th element of a tuple.

Methods

  • _6 :: Lens s t a b

    Access the 6th field of a tuple.

Instances4Field6
  • Field6 (a, b, c, d, e, f) (a, b, c, d, e, f') f f'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field6 (a, b, c, d, e, f, g) (a, b, c, d, e, f', g) f f'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field6 (a, b, c, d, e, f, g, h) (a, b, c, d, e, f', g, h) f f'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field6 (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f', g, h, i) f f'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
classclass Field7 s t a b | s -> a, t -> b, s b -> t, t a -> s where
#

Provide access to the 7th field of a tuple.

Methods

  • _7 :: Lens s t a b

    Access the 7th field of a tuple.

Instances3Field7
  • Field7 (a, b, c, d, e, f, g) (a, b, c, d, e, f, g') g g'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field7 (a, b, c, d, e, f, g, h) (a, b, c, d, e, f, g', h) g g'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field7 (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f, g', h, i) g g'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
classclass Field8 s t a b | s -> a, t -> b, s b -> t, t a -> s where
#

Provide access to the 8th field of a tuple.

Methods

  • _8 :: Lens s t a b

    Access the 8th field of a tuple.

Instances2Field8
  • Field8 (a, b, c, d, e, f, g, h) (a, b, c, d, e, f, g, h') h h'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
  • Field8 (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f, g, h', i) h h'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics
classclass Field9 s t a b | s -> a, t -> b, s b -> t, t a -> s where
#

Provides access to the 9th field of a tuple.

Methods

  • _9 :: Lens s t a b

    Access the 9th field of a tuple.

Instances1Field9
  • Field9 (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f, g, h, i') i i'Defined in optics-core-0.4.1.1 · Data.Tuple.Optics

Strict variations

9 declarations