vinyl-0.8.1.1: Extensible Records

Safe HaskellNone
LanguageHaskell2010

Data.Vinyl.Lens

Description

Lenses into record fields.

Synopsis

Documentation

class i ~ RIndex r rs => RecElem record (r :: k) (rs :: [k]) (i :: Nat) where Source #

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

Minimal complete definition

rlens, rget, rput

Methods

rlens :: Functor g => sing r -> (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:

rlens :: sing r => Lens' (Rec f rs) (f r)

rget :: sing r -> record f rs -> f r Source #

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

rput :: 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
(i ~ RIndex t ts, NatToInt (RIndex t ts)) => RecElem (ARec :: (k -> *) -> [k] -> *) (t :: k) (ts :: [k]) i Source # 
Instance details

Defined in Data.Vinyl.ARec

Methods

rlens :: Functor g => sing t -> (f t -> g (f t)) -> ARec f ts -> g (ARec f ts) Source #

rget :: sing t -> ARec f ts -> f t Source #

rput :: f t -> ARec f ts -> ARec f ts Source #

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

Defined in Data.Vinyl.Lens

Methods

rlens :: Functor g => sing r -> (f r -> g (f r)) -> Rec f (r ': rs) -> g (Rec f (r ': rs)) Source #

rget :: sing r -> Rec f (r ': rs) -> f r Source #

rput :: f r -> Rec f (r ': rs) -> Rec f (r ': rs) Source #

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

Defined in Data.Vinyl.Lens

Methods

rlens :: Functor g => sing r -> (f r -> g (f r)) -> Rec f (s ': rs) -> g (Rec f (s ': rs)) Source #

rget :: sing r -> Rec f (s ': rs) -> f r Source #

rput :: f r -> Rec f (s ': rs) -> Rec f (s ': rs) Source #

type RElem = RecElem Rec Source #

RecElem for classic vinyl Rec types.

class is ~ RImage rs ss => RecSubset record (rs :: [k]) (ss :: [k]) 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

rsubset

Methods

rsubset :: Functor g => (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)

rcast :: 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.

rreplace :: 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 -> *) -> [k] -> *) (rs :: [k]) (ss :: [k]) is Source # 
Instance details

Defined in Data.Vinyl.ARec

Methods

rsubset :: Functor g => (ARec f rs -> g (ARec f rs)) -> ARec f ss -> g (ARec f ss) Source #

rcast :: ARec f ss -> ARec f rs Source #

rreplace :: ARec f rs -> ARec f ss -> ARec f ss Source #

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

Defined in Data.Vinyl.Lens

Methods

rsubset :: Functor g => (Rec f [] -> g (Rec f [])) -> Rec f ss -> g (Rec f ss) Source #

rcast :: Rec f ss -> Rec f [] Source #

rreplace :: Rec f [] -> Rec f ss -> Rec f ss Source #

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

Defined in Data.Vinyl.Lens

Methods

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

rcast :: Rec f ss -> Rec f (r ': rs) Source #

rreplace :: Rec f (r ': rs) -> Rec f ss -> Rec f ss Source #

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 (≅).