Safe Haskell | None |
---|---|
Language | Haskell2010 |
Lenses into record fields.
Synopsis
- class (i ~ RIndex r rs, NatToInt i) => RecElem record (r :: k) (r' :: k) (rs :: [k]) (rs' :: [k]) (i :: Nat) | r r' rs i -> rs' where
- type RecElemFCtx record (f :: k -> *) :: Constraint
- rget :: forall r rs f record. (RecElem record r r rs rs (RIndex r rs), RecElemFCtx record f) => record f rs -> f r
- 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
- 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'
- 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)
- 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')
- type RElem x rs = RecElem Rec x x rs rs
- class is ~ RImage rs ss => RecSubset record (rs :: [k]) (ss :: [k]) is where
- type RecSubsetFCtx record (f :: k -> *) :: Constraint
- 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)
- rcast :: forall rs ss f record is. (RecSubset record rs ss is, RecSubsetFCtx record f) => record f ss -> record f rs
- rreplace :: forall rs ss f record is. (RecSubset record rs ss is, RecSubsetFCtx record f) => record f rs -> record f ss -> record f ss
- type RSubset = RecSubset Rec
- type REquivalent rs ss is js = (RSubset rs ss is, RSubset ss rs js)
- type (∈) r rs = RElem r rs (RIndex r rs)
- type (⊆) rs ss = RSubset rs ss (RImage rs ss)
- type (≅) rs ss = REquivalent rs ss (RImage rs ss) (RImage ss rs)
- type (<:) rs ss = rs ⊆ ss
- type (:~:) rs ss = rs ≅ ss
Documentation
class (i ~ RIndex r rs, NatToInt i) => RecElem record (r :: k) (r' :: k) (rs :: [k]) (rs' :: [k]) (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
.
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.
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 -> *) -> [a] -> *) (r :: a) (r' :: a) (r ': rs :: [a]) (r' ': rs :: [a]) Z Source # | |
Defined in Data.Vinyl.Lens type RecElemFCtx Rec f :: Constraint Source # | |
RecElem (ARec :: (a -> *) -> [a] -> *) (t :: a) (t' :: a) (t ': ts :: [a]) (t' ': ts :: [a]) Z Source # | |
Defined in Data.Vinyl.ARec type RecElemFCtx ARec f :: Constraint Source # | |
(RIndex r (s ': rs) ~ S i, RecElem (Rec :: (a -> *) -> [a] -> *) r r' rs rs' i) => RecElem (Rec :: (a -> *) -> [a] -> *) (r :: a) (r' :: a) (s ': rs :: [a]) (s ': rs' :: [a]) (S i) Source # | |
Defined in Data.Vinyl.Lens type RecElemFCtx Rec f :: Constraint Source # | |
(RIndex t (s ': ts) ~ S i, NatToInt i, RecElem (ARec :: (a -> *) -> [a] -> *) t t' ts ts' i) => RecElem (ARec :: (a -> *) -> [a] -> *) (t :: a) (t' :: a) (s ': ts :: [a]) (s ': ts' :: [a]) (S i) Source # | |
Defined in Data.Vinyl.ARec type RecElemFCtx ARec f :: Constraint Source # | |
(i ~ RIndex t ts, NatToInt i, FieldOffset ElField ts t, Storable (Rec ElField ts), AllConstrained (FieldOffset ElField ts) ts) => RecElem (SRec :: ((Symbol, *) -> *) -> [(Symbol, *)] -> *) (t :: (Symbol, *)) (t :: (Symbol, *)) (ts :: [(Symbol, *)]) (ts :: [(Symbol, *)]) i Source # | |
Defined in Data.Vinyl.SRec type RecElemFCtx SRec f :: Constraint 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 |
Defined in Data.Vinyl.SRec type RecElemFCtx (SRec2 ElField) f :: Constraint Source # 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
.
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.
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.
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 #
Instances
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
.
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 (⊆) 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.