Safe Haskell | None |
---|---|
Language | Haskell2010 |
Lenses into record fields.
Synopsis
- class (i ~ RIndex r rs, NatToInt i) => RecElem (record :: (k -> *) -> [k] -> *) (r :: k) (r' :: k) (rs :: [k]) (rs' :: [k]) (i :: Nat) | r r' rs i -> rs' where
- type RecElemFCtx record (f :: k -> *) :: Constraint
- rlensC :: (Functor g, RecElemFCtx record f) => (f r -> g (f r')) -> record f rs -> g (record f rs')
- rgetC :: (RecElemFCtx record f, r ~ r') => record f rs -> f r
- rputC :: RecElemFCtx record f => f r' -> record f rs -> record f rs'
- 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 k (r :: k) 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 k (r :: k) (r' :: k) (rs :: [k]) (rs' :: [k]) 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 ss is where
- type RecSubsetFCtx record (f :: k -> *) :: Constraint
- rsubsetC :: (Functor g, RecSubsetFCtx record f) => (record f rs -> g (record f rs)) -> record f ss -> g (record f ss)
- rcastC :: RecSubsetFCtx record f => record f ss -> record f rs
- rreplaceC :: RecSubsetFCtx record f => record f rs -> record f ss -> record f ss
- rsubset :: forall k 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
- rdowncast :: (RecApplicative ss, RMap rs, rs ⊆ ss) => Rec f rs -> Rec (Maybe :. 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 :: (k -> *) -> [k] -> *) (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.
type RecElemFCtx record f = ()
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 # | |
Defined in Data.Vinyl.Lens type RecElemFCtx Rec f Source # | |
RecElem (ARec :: (a -> Type) -> [a] -> Type) (t :: a) (t' :: a) (t ': ts :: [a]) (t' ': ts :: [a]) 'Z Source # | |
Defined in Data.Vinyl.ARec.Internal type RecElemFCtx ARec f 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 # | |
Defined in Data.Vinyl.Lens type RecElemFCtx Rec f 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 # | |
Defined in Data.Vinyl.ARec.Internal type RecElemFCtx ARec f 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 # | |
(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 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 k (r :: k) 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 k (r :: k) (r' :: k) (rs :: [k]) (rs' :: [k]) 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 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.
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.
type RecSubsetFCtx record f = ()
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
(is ~ RImage rs ss, IndexWitnesses is, NatToInt (RLength rs)) => RecSubset (ARec :: (k -> Type) -> [k] -> Type) (rs :: [k]) (ss :: [k]) is Source # | |
Defined in Data.Vinyl.ARec.Internal type RecSubsetFCtx ARec f Source # rsubsetC :: forall g (f :: k0 -> Type). (Functor g, RecSubsetFCtx ARec f) => (ARec f rs -> g (ARec f rs)) -> ARec f ss -> g (ARec f ss) Source # rcastC :: forall (f :: k0 -> Type). RecSubsetFCtx ARec f => ARec f ss -> ARec f rs Source # rreplaceC :: forall (f :: k0 -> Type). RecSubsetFCtx ARec f => ARec f rs -> ARec f ss -> ARec f ss Source # | |
RecSubset (Rec :: (k -> Type) -> [k] -> Type) ('[] :: [k]) (ss :: [k]) ('[] :: [Nat]) Source # | |
Defined in Data.Vinyl.Lens type RecSubsetFCtx Rec f Source # rsubsetC :: forall g (f :: k0 -> Type). (Functor g, RecSubsetFCtx Rec f) => (Rec f '[] -> g (Rec f '[])) -> Rec f ss -> g (Rec f ss) Source # rcastC :: forall (f :: k0 -> Type). RecSubsetFCtx Rec f => Rec f ss -> Rec f '[] Source # rreplaceC :: forall (f :: k0 -> Type). 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 # | |
Defined in Data.Vinyl.Lens type RecSubsetFCtx Rec f Source # rsubsetC :: forall g (f :: k0 -> Type). (Functor g, RecSubsetFCtx Rec f) => (Rec f (r ': rs) -> g (Rec f (r ': rs))) -> Rec f ss -> g (Rec f ss) Source # rcastC :: forall (f :: k0 -> Type). RecSubsetFCtx Rec f => Rec f ss -> Rec f (r ': rs) Source # rreplaceC :: forall (f :: k0 -> Type). 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 # | |
Defined in Data.Vinyl.SRec type RecSubsetFCtx SRec f Source # rsubsetC :: forall g (f :: k -> Type). (Functor g, RecSubsetFCtx SRec f) => (SRec f rs -> g (SRec f rs)) -> SRec f ss -> g (SRec f ss) Source # rcastC :: forall (f :: k -> Type). RecSubsetFCtx SRec f => SRec f ss -> SRec f rs Source # rreplaceC :: forall (f :: k -> Type). 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 # | |
Defined in Data.Vinyl.SRec type RecSubsetFCtx (SRec2 ElField) f Source # rsubsetC :: forall g (f :: k -> Type). (Functor g, RecSubsetFCtx (SRec2 ElField) f) => (SRec2 ElField f rs -> g (SRec2 ElField f rs)) -> SRec2 ElField f ss -> g (SRec2 ElField f ss) Source # rcastC :: forall (f :: k -> Type). RecSubsetFCtx (SRec2 ElField) f => SRec2 ElField f ss -> SRec2 ElField f rs Source # rreplaceC :: forall (f :: k -> Type). RecSubsetFCtx (SRec2 ElField) f => SRec2 ElField f rs -> SRec2 ElField f ss -> SRec2 ElField f ss Source # |
rsubset :: forall k 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.