vinyl-0.12.1: Extensible Records

Safe HaskellNone
LanguageHaskell2010

Data.Vinyl.Lens

Description

Lenses into record fields.

Synopsis

Documentation

class (i ~ RIndex r rs, NatToInt i) => RecElem record r r' rs rs' (i :: Nat) | r r' rs i -> rs' where Source #

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 RecElemFCtx record (f :: k -> *) :: Constraint Source #

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') Source #

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 Source #

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' Source #

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.

Instances
RecElem (Rec :: (a -> Type) -> [a] -> Type) (r :: a) (r' :: a) (r ': rs :: [a]) (r' ': rs :: [a]) Z Source # 
Instance details

Defined in Data.Vinyl.Lens

Associated Types

type RecElemFCtx Rec f :: Constraint Source #

Methods

rlensC :: (Functor g, RecElemFCtx Rec f) => (f r -> g (f r')) -> Rec f (r ': rs) -> g (Rec f (r' ': rs)) Source #

rgetC :: (RecElemFCtx Rec f, r ~ r') => Rec f (r ': rs) -> f r Source #

rputC :: RecElemFCtx Rec f => f r' -> Rec f (r ': rs) -> Rec f (r' ': rs) Source #

RecElem (ARec :: (a -> Type) -> [a] -> Type) (t :: a) (t' :: a) (t ': ts :: [a]) (t' ': ts :: [a]) Z Source # 
Instance details

Defined in Data.Vinyl.ARec

Associated Types

type RecElemFCtx ARec f :: Constraint Source #

Methods

rlensC :: (Functor g, RecElemFCtx ARec f) => (f t -> g (f t')) -> ARec f (t ': ts) -> g (ARec f (t' ': ts)) Source #

rgetC :: (RecElemFCtx ARec f, t ~ t') => ARec f (t ': ts) -> f t Source #

rputC :: RecElemFCtx ARec f => f t' -> ARec f (t ': ts) -> ARec f (t' ': ts) Source #

(RIndex r (s ': rs) ~ S i, RecElem (Rec :: (a -> Type) -> [a] -> Type) r r' rs rs' i) => RecElem (Rec :: (a -> Type) -> [a] -> Type) (r :: a) (r' :: a) (s ': rs :: [a]) (s ': rs' :: [a]) (S i) Source # 
Instance details

Defined in Data.Vinyl.Lens

Associated Types

type RecElemFCtx Rec f :: Constraint Source #

Methods

rlensC :: (Functor g, RecElemFCtx Rec f) => (f r -> g (f r')) -> Rec f (s ': rs) -> g (Rec f (s ': rs')) Source #

rgetC :: (RecElemFCtx Rec f, r ~ r') => Rec f (s ': rs) -> f r Source #

rputC :: RecElemFCtx Rec f => f r' -> Rec f (s ': rs) -> Rec f (s ': rs') Source #

(RIndex t (s ': ts) ~ S i, NatToInt i, RecElem (ARec :: (a -> Type) -> [a] -> Type) t t' ts ts' i) => RecElem (ARec :: (a -> Type) -> [a] -> Type) (t :: a) (t' :: a) (s ': ts :: [a]) (s ': ts' :: [a]) (S i) Source # 
Instance details

Defined in Data.Vinyl.ARec

Associated Types

type RecElemFCtx ARec f :: Constraint Source #

Methods

rlensC :: (Functor g, RecElemFCtx ARec f) => (f t -> g (f t')) -> ARec f (s ': ts) -> g (ARec f (s ': ts')) Source #

rgetC :: (RecElemFCtx ARec f, t ~ t') => ARec f (s ': ts) -> f t Source #

rputC :: RecElemFCtx ARec f => f t' -> ARec f (s ': ts) -> ARec f (s ': ts') Source #

(i ~ RIndex t ts, NatToInt i, FieldOffset ElField ts t, Storable (Rec ElField ts), AllConstrained (FieldOffset ElField ts) ts) => RecElem (SRec :: ((Symbol, Type) -> Type) -> [(Symbol, Type)] -> Type) (t :: (Symbol, Type)) (t :: (Symbol, Type)) (ts :: [(Symbol, Type)]) (ts :: [(Symbol, Type)]) i Source # 
Instance details

Defined in Data.Vinyl.SRec

Associated Types

type RecElemFCtx SRec f :: Constraint Source #

Methods

rlensC :: (Functor g, RecElemFCtx SRec f) => (f t -> g (f t)) -> SRec f ts -> g (SRec f ts) Source #

rgetC :: (RecElemFCtx SRec f, t ~ t) => SRec f ts -> f t Source #

rputC :: RecElemFCtx SRec f => f t -> SRec f ts -> SRec f ts Source #

(i ~ RIndex t ts, NatToInt i, FieldOffset ElField ts t, Storable (Rec ElField ts), AllConstrained (FieldOffset ElField ts) ts) => RecElem (SRec2 ElField) (t :: (Symbol, Type)) (t :: (Symbol, Type)) (ts :: [(Symbol, Type)]) (ts :: [(Symbol, Type)]) i Source #

Field accessors for SRec2 specialized to ElField as the functor.

Instance details

Defined in Data.Vinyl.SRec

Associated Types

type RecElemFCtx (SRec2 ElField) f :: Constraint Source #

Methods

rlensC :: (Functor g, RecElemFCtx (SRec2 ElField) f) => (f t -> g (f t)) -> SRec2 ElField f ts -> g (SRec2 ElField f ts) Source #

rgetC :: (RecElemFCtx (SRec2 ElField) f, t ~ t) => SRec2 ElField f ts -> f t Source #

rputC :: RecElemFCtx (SRec2 ElField) f => f t -> SRec2 ElField f ts -> SRec2 ElField f ts Source #

rget :: forall r rs f record. (RecElem record r r rs rs (RIndex r rs), RecElemFCtx record f) => record f rs -> f r Source #

rput :: forall r rs record f. (RecElem record r r rs rs (RIndex r rs), RecElemFCtx record f) => f r -> record f rs -> record f rs Source #

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

rput' :: forall r r' rs rs' record f. (RecElem record r r' rs rs' (RIndex r rs), RecElemFCtx record f) => f r' -> record f rs -> record f rs' Source #

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

rlens :: forall r record rs f g. (RecElem record r r rs rs (RIndex r rs), RecElemFCtx record f, Functor g) => (f r -> g (f r)) -> record f rs -> g (record f rs) Source #

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

rlens' :: forall r r' record rs rs' f g. (RecElem record r r' rs rs' (RIndex r rs), RecElemFCtx record f, Functor g) => (f r -> g (f r')) -> record f rs -> g (record f rs') Source #

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

type RElem x rs = RecElem Rec x x rs rs Source #

RecElem for classic vinyl Rec types.

class is ~ RImage rs ss => RecSubset record rs ss is where Source #

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.

Minimal complete definition

rsubsetC

Associated Types

type RecSubsetFCtx record (f :: k -> *) :: Constraint Source #

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) Source #

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 Source #

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 Source #

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

Instances
(is ~ RImage rs ss, IndexWitnesses is, NatToInt (RLength rs)) => RecSubset (ARec :: (k -> Type) -> [k] -> Type) (rs :: [k]) (ss :: [k]) is Source # 
Instance details

Defined in Data.Vinyl.ARec

Associated Types

type RecSubsetFCtx ARec f :: Constraint Source #

Methods

rsubsetC :: (Functor g, RecSubsetFCtx ARec f) => (ARec f rs -> g (ARec f rs)) -> ARec f ss -> g (ARec f ss) Source #

rcastC :: RecSubsetFCtx ARec f => ARec f ss -> ARec f rs Source #

rreplaceC :: RecSubsetFCtx ARec f => ARec f rs -> ARec f ss -> ARec f ss Source #

RecSubset (Rec :: (k -> Type) -> [k] -> Type) ([] :: [k]) (ss :: [k]) ([] :: [Nat]) Source # 
Instance details

Defined in Data.Vinyl.Lens

Associated Types

type RecSubsetFCtx Rec f :: Constraint Source #

Methods

rsubsetC :: (Functor g, RecSubsetFCtx Rec f) => (Rec f [] -> g (Rec f [])) -> Rec f ss -> g (Rec f ss) Source #

rcastC :: RecSubsetFCtx Rec f => Rec f ss -> Rec f [] Source #

rreplaceC :: RecSubsetFCtx Rec f => Rec f [] -> Rec f ss -> Rec f ss Source #

(RElem r ss i, RSubset rs ss is) => RecSubset (Rec :: (k -> Type) -> [k] -> Type) (r ': rs :: [k]) (ss :: [k]) (i ': is) Source # 
Instance details

Defined in Data.Vinyl.Lens

Associated Types

type RecSubsetFCtx Rec f :: Constraint Source #

Methods

rsubsetC :: (Functor g, RecSubsetFCtx Rec f) => (Rec f (r ': rs) -> g (Rec f (r ': rs))) -> Rec f ss -> g (Rec f ss) Source #

rcastC :: RecSubsetFCtx Rec f => Rec f ss -> Rec f (r ': rs) Source #

rreplaceC :: RecSubsetFCtx Rec f => Rec f (r ': rs) -> Rec f ss -> Rec f ss Source #

(is ~ RImage rs ss, RecSubset (Rec :: ((Symbol, Type) -> Type) -> [(Symbol, Type)] -> Type) rs ss is, Storable (Rec ElField rs), Storable (Rec ElField ss), RPureConstrained (FieldOffset ElField ss) rs, RPureConstrained (FieldOffset ElField rs) rs, RFoldMap rs, RMap rs, RApply rs) => RecSubset (SRec :: ((Symbol, Type) -> Type) -> [(Symbol, Type)] -> Type) (rs :: [(Symbol, Type)]) (ss :: [(Symbol, Type)]) is Source # 
Instance details

Defined in Data.Vinyl.SRec

Associated Types

type RecSubsetFCtx SRec f :: Constraint Source #

Methods

rsubsetC :: (Functor g, RecSubsetFCtx SRec f) => (SRec f rs -> g (SRec f rs)) -> SRec f ss -> g (SRec f ss) Source #

rcastC :: RecSubsetFCtx SRec f => SRec f ss -> SRec f rs Source #

rreplaceC :: RecSubsetFCtx SRec f => SRec f rs -> SRec f ss -> SRec f ss Source #

(is ~ RImage rs ss, RecSubset (Rec :: ((Symbol, Type) -> Type) -> [(Symbol, Type)] -> Type) rs ss is, Storable (Rec ElField rs), Storable (Rec ElField ss), RPureConstrained (FieldOffset ElField ss) rs, RPureConstrained (FieldOffset ElField rs) rs, RFoldMap rs, RMap rs, RApply rs) => RecSubset (SRec2 ElField) (rs :: [(Symbol, Type)]) (ss :: [(Symbol, Type)]) is Source # 
Instance details

Defined in Data.Vinyl.SRec

Associated Types

type RecSubsetFCtx (SRec2 ElField) f :: Constraint Source #

rsubset :: forall rs ss f g record is. (RecSubset record (rs :: [k]) (ss :: [k]) is, Functor g, RecSubsetFCtx record f) => (record f rs -> g (record f rs)) -> record f ss -> g (record f ss) Source #

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

rcast :: forall rs ss f record is. (RecSubset record rs ss is, RecSubsetFCtx record f) => record f ss -> record f rs Source #

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.

rreplace :: forall rs ss f record is. (RecSubset record rs ss is, RecSubsetFCtx record f) => record f rs -> record f ss -> record f ss Source #

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.

rdowncast :: (RecApplicative ss, RMap rs, rs ss) => Rec f rs -> Rec (Maybe :. f) ss Source #

Takes a smaller record to a larger one, a downcast, by layering a Maybe interpretation that lets us use Nothing for the fields not present in the smaller record.

type REquivalent rs ss is js = (RSubset rs ss is, RSubset ss rs js) Source #

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

type (∈) r rs = RElem r rs (RIndex r rs) Source #

A shorthand for RElem which supplies its index.

type (⊆) rs ss = RSubset rs ss (RImage rs ss) Source #

A shorthand for RSubset which supplies its image.

type (≅) rs ss = REquivalent rs ss (RImage rs ss) (RImage ss rs) Source #

A shorthand for REquivalent which supplies its images.

type (<:) rs ss = rs ss Source #

A non-unicode equivalent of (⊆).

type (:~:) rs ss = rs ss Source #

A non-unicode equivalent of (≅).