generic-lens-2.2.1.0: Generically derive traversals, lenses and prisms.
Copyright (C) 2020 Csongor Kiss
License BSD3
Maintainer Csongor Kiss <kiss.csongor.kiss@gmail.com>
Stability experimental
Portability non-portable
Safe Haskell None
Language Haskell2010

Data.Generics.Product.Positions

Contents

Description

Derive positional product type getters and setters generically.

Synopsis

Lenses

Running example:

>>> :set -XTypeApplications
>>> :set -XDataKinds
>>> :set -XDeriveGeneric
>>> :set -XGADTs
>>> :set -XFlexibleContexts
>>> import GHC.Generics
>>> :m +Data.Generics.Internal.VL.Lens
>>> :m +Data.Function
>>> :{
data Human = Human
  { name    :: String
  , age     :: Int
  , address :: String
  }
  deriving (Generic, Show)
human :: Human
human = Human "Tunyasz" 50 "London"
:}

class HasPosition (i :: Nat ) s t a b | s i -> a, t i -> b, s i b -> t, t i a -> s where Source #

Records that have a field at a given position.

Methods

position :: Lens s t a b Source #

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

>>> human ^. position @1
"Tunyasz"
>>> human & position @3 .~ "Berlin"
Human {name = "Tunyasz", age = 50, address = "Berlin"}

Type errors

>>> human & position @4 .~ "Berlin"
...
... The type Human does not contain a field at position 4
...

Instances

Instances details
( Context i s t a b, HasPosition0 i s t a b) => HasPosition i s t a b Source #
Instance details

Defined in Data.Generics.Product.Positions

HasPosition f ( Void1 a) ( Void1 b) a b Source #

See Note [Uncluttering type signatures] >>> :t +d position position :: (HasPosition i s t a b, Functor f) => (a -> f b) -> s -> f t

Instance details

Defined in Data.Generics.Product.Positions

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

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

Instances

Instances details
Context' i s a => HasPosition' i s a Source #
Instance details

Defined in Data.Generics.Product.Positions

class HasPosition_ (i :: Nat ) s t a b where Source #

Instances

Instances details
( Context_ i s t a b, HasPosition0 i s t a b) => HasPosition_ i s t a b Source #
Instance details

Defined in Data.Generics.Product.Positions

HasPosition_ f ( Void1 a) ( Void1 b) a b Source #
Instance details

Defined in Data.Generics.Product.Positions

class HasPosition0 (i :: Nat ) s t a b where Source #

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 .

Instances

Instances details
Context0 i s t a b => HasPosition0 i s t a b Source #
Instance details

Defined in Data.Generics.Product.Positions

getPosition :: forall i s a. HasPosition' i s a => s -> a Source #

>>> getPosition @2 human
50

setPosition :: forall i s a. HasPosition' i s a => a -> s -> s Source #

>>> setPosition @2 60 human
Human {name = "Tunyasz", age = 60, address = "London"}