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

Modulevinyl-0.14.3Haskell2010

Data.Vinyl.Lens

Lenses into record fields.

  • 8 types
  • 2 classes
  • 9 values
  • Packagevinyl-0.14.3
  • Exports19
  • LanguageHaskell2010
  • LicenceMIT
  • SourceLens.hs
classclass (i ~ RIndex r rs, NatToInt i) => RecElem (record :: (k -> Type) -> [k] -> Type) (r :: k) (r' :: k) (rs :: [k]) (rs' :: [k]) (i :: Nat) | r r' rs i -> rs' where
#

The presence of a field in a record is witnessed by a lens into its value. The fifth parameter to RecElem, i, is there to help the constraint solver realize that this is a decidable predicate with respect to the judgemental equality in k.

Associated types

  • type family RecElemFCtx (record :: (k -> Type) -> [k] -> Type) (f :: k -> Type) :: Constraint

    An opportunity for instances to generate constraints based on the functor parameter of records passed to class methods.

Methods

  • rlensC :: (Functor g, RecElemFCtx record f) => (f r -> g (f r')) -> record f rs -> g (record f rs')

    We can get a lens for getting and setting the value of a field which is in a record. As a convenience, we take a proxy argument to fix the particular field being viewed. These lenses are compatible with the lens library. Morally:

    rlensC :: Lens' (Rec f rs) (Rec f rs') (f r) (f r')
  • rgetC :: (RecElemFCtx record f, r ~ r') => record f rs -> f r

    For Vinyl users who are not using the lens package, we provide a getter.

  • rputC :: RecElemFCtx record f => f r' -> record f rs -> record f rs'

    For Vinyl users who are not using the lens package, we also provide a setter. In general, it will be unambiguous what field is being written to, and so we do not take a proxy argument here.

Instances6RecElem
valuerput
  1. :: (RecElem record r r rs rs (RIndex r rs), RecElemFCtx record f)
  2. => f r
  3. -> record f rs
  4. -> record f rs
#

Type-preserving field setter. This type is simpler to work with than that of rput'.

valuerput'
  1. :: (RecElem record r r' rs rs' (RIndex r rs), RecElemFCtx record f)
  2. => f r'
  3. -> record f rs
  4. -> record f rs'
#

The type-changing field setter rputC with the type arguments re-ordered for more convenient usage with TypeApplications.

valuerlens
  1. :: (RecElem record r r rs rs (RIndex r rs), RecElemFCtx record f, Functor g)
  2. => f r -> g (f r)
  3. -> record f rs
  4. -> g (record f rs)
#

Type-preserving field lens. This type is simpler to work with than that of rlens'.

valuerlens'
  1. :: (RecElem record r r' rs rs' (RIndex r rs), RecElemFCtx record f, Functor g)
  2. => f r -> g (f r')
  3. -> record f rs
  4. -> g (record f rs')
#

Type-changing field lens rlensC with the type arguments re-ordered for more convenient usage with TypeApplications.

classclass is ~ RImage rs ss => RecSubset (record :: (k -> Type) -> [k1] -> Type) (rs :: [k1]) (ss :: [k1]) (is :: [Nat]) where
#

If one field set is a subset another, then a lens of from the latter's record to the former's is evident. That is, we can either cast a larger record to a smaller one, or we may replace the values in a slice of a record.

Associated types

  • type family RecSubsetFCtx (record :: (k -> Type) -> [k1] -> Type) (f :: k -> Type) :: Constraint

    An opportunity for instances to generate constraints based on the functor parameter of records passed to class methods.

Methods

  • rsubsetC :: (Functor g, RecSubsetFCtx record f) => (record f rs -> g (record f rs)) -> record f ss -> g (record f ss)

    This is a lens into a slice of the larger record. Morally, we have:

    rsubset :: Lens' (Rec f ss) (Rec f rs)
  • rcastC :: RecSubsetFCtx record f => record f ss -> record f rs

    The getter of the rsubset lens is rcast, which takes a larger record to a smaller one by forgetting fields.

  • rreplaceC :: RecSubsetFCtx record f => record f rs -> record f ss -> record f ss

    The setter of the rsubset lens is rreplace, which allows a slice of a record to be replaced with different values.

Instances5RecSubset
valuersubset
  1. :: (RecSubset record rs ss is, Functor g, RecSubsetFCtx record f)
  2. => record f rs -> g (record f rs)
  3. -> record f ss
  4. -> g (record f ss)
#

A lens into a slice of the larger record. This is rsubsetC with the type arguments reordered for more convenient usage with TypeApplications.

valuercast
  1. :: (RecSubset record rs ss is, RecSubsetFCtx record f)
  2. => record f ss
  3. -> record f rs
#

Takes a larger record to a smaller one by forgetting fields. This is rcastC with the type arguments reordered for more convenient usage with TypeApplications.

valuerreplace
  1. :: (RecSubset record rs ss is, RecSubsetFCtx record f)
  2. => record f rs
  3. -> record f ss
  4. -> record f ss
#

Allows a slice of a record to be replaced with different values. This is rreplaceC with the type arguments reordered for more convenient usage with TypeApplications.

typetype REquivalent (rs :: [k]) (ss :: [k]) (is :: [Nat]) (js :: [Nat]) = (RSubset rs ss is, RSubset ss rs js)
#

Two record types are equivalent when they are subtypes of each other.

typetype (∈) (r :: k) (rs :: [k]) = RElem r rs (RIndex r rs)
#

A shorthand for RElem which supplies its index.

typetype (⊆) (rs :: [k]) (ss :: [k]) = RSubset rs ss (RImage rs ss)
#

A shorthand for RSubset which supplies its image.

typetype (<:) (rs :: [k]) (ss :: [k]) = rs ⊆ ss
#

A non-unicode equivalent of (⊆).

typetype (:~:) (rs :: [k]) (ss :: [k]) = rs ≅ ss
#

A non-unicode equivalent of (≅).