| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Vinyl.Lens
Description
Lenses into record fields.
Synopsis
- class (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
- type RecElemFCtx (record :: (k -> Type) -> [k] -> Type) (f :: k -> Type)
- 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 {k} (r :: k) (rs :: [k]) 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 :: [k]) 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 {k} (r :: k) record (rs :: [k]) 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 {k} (r :: k) (r' :: k) record (rs :: [k]) (rs' :: [k]) 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 :: k) (rs :: [k]) = RecElem (Rec :: (k -> Type) -> [k] -> Type) x x rs rs
- class is ~ RImage rs ss => RecSubset (record :: (k -> Type) -> [k1] -> Type) (rs :: [k1]) (ss :: [k1]) (is :: [Nat]) where
- type RecSubsetFCtx (record :: (k -> Type) -> [k1] -> Type) (f :: k -> Type)
- rsubsetC :: forall g (f :: k -> Type). (Functor g, RecSubsetFCtx record f) => (record f rs -> g (record f rs)) -> record f ss -> g (record f ss)
- rcastC :: forall (f :: k -> Type). RecSubsetFCtx record f => record f ss -> record f rs
- rreplaceC :: forall (f :: k -> Type). RecSubsetFCtx record f => record f rs -> record f ss -> record f ss
- rsubset :: forall {k1} k2 (rs :: [k2]) (ss :: [k2]) (f :: k1 -> Type) g record (is :: [Nat]). (RecSubset record rs ss is, Functor g, RecSubsetFCtx record f) => (record f rs -> g (record f rs)) -> record f ss -> g (record f ss)
- rcast :: forall {k1} {k2} (rs :: [k1]) (ss :: [k1]) (f :: k2 -> Type) record (is :: [Nat]). (RecSubset record rs ss is, RecSubsetFCtx record f) => record f ss -> record f rs
- rreplace :: forall {k1} {k2} (rs :: [k1]) (ss :: [k1]) (f :: k2 -> Type) record (is :: [Nat]). (RecSubset record rs ss is, RecSubsetFCtx record f) => record f rs -> record f ss -> record f ss
- rdowncast :: forall {u} (ss :: [u]) (rs :: [u]) (f :: u -> Type). (RecApplicative ss, RMap rs, rs ⊆ ss) => Rec f rs -> Rec (Maybe :. f) ss
- type RSubset = RecSubset (Rec :: (k -> Type) -> [k] -> Type)
- type REquivalent (rs :: [k]) (ss :: [k]) (is :: [Nat]) (js :: [Nat]) = (RSubset rs ss is, RSubset ss rs js)
- type (∈) (r :: k) (rs :: [k]) = RElem r rs (RIndex r rs)
- type (⊆) (rs :: [k]) (ss :: [k]) = RSubset rs ss (RImage rs ss)
- type (≅) (rs :: [k]) (ss :: [k]) = REquivalent rs ss (RImage rs ss) (RImage ss rs)
- type (<:) (rs :: [k]) (ss :: [k]) = rs ⊆ ss
- type (:~:) (rs :: [k]) (ss :: [k]) = rs ≅ ss
Documentation
class (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 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 :: (k -> Type) -> [k] -> Type) (f :: k -> Type) Source #
An opportunity for instances to generate constraints based on the functor parameter of records passed to class methods.
type RecElemFCtx (record :: (k -> Type) -> [k] -> Type) (f :: k -> Type) = ()
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 (ARec :: (a -> Type) -> [a] -> Type) (t :: a) (t' :: a) (t ': ts :: [a]) (t' ': ts :: [a]) 'Z Source # | |||||
Defined in Data.Vinyl.ARec.Internal Methods rlensC :: (Functor g, RecElemFCtx (ARec :: (a -> Type) -> [a] -> Type) f) => (f t -> g (f t')) -> ARec f (t ': ts) -> g (ARec f (t' ': ts)) Source # rgetC :: (RecElemFCtx (ARec :: (a -> Type) -> [a] -> Type) f, t ~ t') => ARec f (t ': ts) -> f t Source # rputC :: RecElemFCtx (ARec :: (a -> Type) -> [a] -> Type) f => f t' -> ARec f (t ': ts) -> ARec f (t' ': ts) Source # | |||||
| RecElem (Rec :: (a -> Type) -> [a] -> Type) (r :: a) (r' :: a) (r ': rs :: [a]) (r' ': rs :: [a]) 'Z Source # | |||||
Defined in Data.Vinyl.Lens Methods rlensC :: (Functor g, RecElemFCtx (Rec :: (a -> Type) -> [a] -> Type) f) => (f r -> g (f r')) -> Rec f (r ': rs) -> g (Rec f (r' ': rs)) Source # rgetC :: (RecElemFCtx (Rec :: (a -> Type) -> [a] -> Type) f, r ~ r') => Rec f (r ': rs) -> f r Source # rputC :: RecElemFCtx (Rec :: (a -> Type) -> [a] -> Type) f => f r' -> Rec f (r ': rs) -> Rec f (r' ': 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 # | |||||
Defined in Data.Vinyl.ARec.Internal Methods rlensC :: (Functor g, RecElemFCtx (ARec :: (a -> Type) -> [a] -> Type) f) => (f t -> g (f t')) -> ARec f (s ': ts) -> g (ARec f (s ': ts')) Source # rgetC :: (RecElemFCtx (ARec :: (a -> Type) -> [a] -> Type) f, t ~ t') => ARec f (s ': ts) -> f t Source # rputC :: RecElemFCtx (ARec :: (a -> Type) -> [a] -> Type) f => f t' -> ARec f (s ': ts) -> ARec f (s ': 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 # | |||||
Defined in Data.Vinyl.Lens Methods rlensC :: (Functor g, RecElemFCtx (Rec :: (a -> Type) -> [a] -> Type) f) => (f r -> g (f r')) -> Rec f (s ': rs) -> g (Rec f (s ': rs')) Source # rgetC :: (RecElemFCtx (Rec :: (a -> Type) -> [a] -> Type) f, r ~ r') => Rec f (s ': rs) -> f r Source # rputC :: RecElemFCtx (Rec :: (a -> Type) -> [a] -> Type) f => f r' -> Rec f (s ': rs) -> Rec f (s ': rs') 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 # | |||||
Defined in Data.Vinyl.SRec Associated Types
Methods rlensC :: (Functor g, RecElemFCtx (SRec :: ((Symbol, Type) -> Type) -> [(Symbol, Type)] -> Type) f) => (f t -> g (f t)) -> SRec f ts -> g (SRec f ts) Source # rgetC :: (RecElemFCtx (SRec :: ((Symbol, Type) -> Type) -> [(Symbol, Type)] -> Type) f, t ~ t) => SRec f ts -> f t Source # rputC :: RecElemFCtx (SRec :: ((Symbol, Type) -> Type) -> [(Symbol, Type)] -> Type) 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 | ||||
Defined in Data.Vinyl.SRec Associated Types
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 {k} (r :: k) (rs :: [k]) 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 :: [k]) 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 {k} (r :: k) record (rs :: [k]) 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 {k} (r :: k) (r' :: k) record (rs :: [k]) (rs' :: [k]) 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 :: (k -> Type) -> [k1] -> Type) (rs :: [k1]) (ss :: [k1]) (is :: [Nat]) 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
Associated Types
type RecSubsetFCtx (record :: (k -> Type) -> [k1] -> Type) (f :: k -> Type) Source #
An opportunity for instances to generate constraints based on the functor parameter of records passed to class methods.
type RecSubsetFCtx (record :: (k -> Type) -> [k1] -> Type) (f :: k -> Type) = ()
Methods
rsubsetC :: forall g (f :: k -> Type). (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 :: forall (f :: k -> Type). 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 :: forall (f :: k -> Type). 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 :: (k1 -> Type) -> [k1] -> Type) (rs :: [k1]) (ss :: [k1]) is Source # | |||||
Defined in Data.Vinyl.ARec.Internal Methods rsubsetC :: forall g (f :: k1 -> Type). (Functor g, RecSubsetFCtx (ARec :: (k1 -> Type) -> [k1] -> Type) f) => (ARec f rs -> g (ARec f rs)) -> ARec f ss -> g (ARec f ss) Source # rcastC :: forall (f :: k1 -> Type). RecSubsetFCtx (ARec :: (k1 -> Type) -> [k1] -> Type) f => ARec f ss -> ARec f rs Source # rreplaceC :: forall (f :: k1 -> Type). RecSubsetFCtx (ARec :: (k1 -> Type) -> [k1] -> Type) 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 Methods rsubsetC :: forall g (f :: k -> Type). (Functor g, RecSubsetFCtx (Rec :: (k -> Type) -> [k] -> Type) f) => (Rec f ('[] :: [k]) -> g (Rec f ('[] :: [k]))) -> Rec f ss -> g (Rec f ss) Source # rcastC :: forall (f :: k -> Type). RecSubsetFCtx (Rec :: (k -> Type) -> [k] -> Type) f => Rec f ss -> Rec f ('[] :: [k]) Source # rreplaceC :: forall (f :: k -> Type). RecSubsetFCtx (Rec :: (k -> Type) -> [k] -> Type) f => Rec f ('[] :: [k]) -> 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 Methods rsubsetC :: forall g (f :: k -> Type). (Functor g, RecSubsetFCtx (Rec :: (k -> Type) -> [k] -> Type) f) => (Rec f (r ': rs) -> g (Rec f (r ': rs))) -> Rec f ss -> g (Rec f ss) Source # rcastC :: forall (f :: k -> Type). RecSubsetFCtx (Rec :: (k -> Type) -> [k] -> Type) f => Rec f ss -> Rec f (r ': rs) Source # rreplaceC :: forall (f :: k -> Type). RecSubsetFCtx (Rec :: (k -> Type) -> [k] -> Type) 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 Associated Types
Methods rsubsetC :: forall g (f :: (Symbol, Type) -> Type). (Functor g, RecSubsetFCtx (SRec :: ((Symbol, Type) -> Type) -> [(Symbol, Type)] -> Type) f) => (SRec f rs -> g (SRec f rs)) -> SRec f ss -> g (SRec f ss) Source # rcastC :: forall (f :: (Symbol, Type) -> Type). RecSubsetFCtx (SRec :: ((Symbol, Type) -> Type) -> [(Symbol, Type)] -> Type) f => SRec f ss -> SRec f rs Source # rreplaceC :: forall (f :: (Symbol, Type) -> Type). RecSubsetFCtx (SRec :: ((Symbol, Type) -> Type) -> [(Symbol, Type)] -> Type) 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 Associated Types
Methods rsubsetC :: forall g (f :: (Symbol, Type) -> 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 :: (Symbol, Type) -> Type). RecSubsetFCtx (SRec2 ElField) f => SRec2 ElField f ss -> SRec2 ElField f rs Source # rreplaceC :: forall (f :: (Symbol, Type) -> Type). RecSubsetFCtx (SRec2 ElField) f => SRec2 ElField f rs -> SRec2 ElField f ss -> SRec2 ElField f ss Source # | |||||
rsubset :: forall {k1} k2 (rs :: [k2]) (ss :: [k2]) (f :: k1 -> Type) g record (is :: [Nat]). (RecSubset record rs ss 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 {k1} {k2} (rs :: [k1]) (ss :: [k1]) (f :: k2 -> Type) record (is :: [Nat]). (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 {k1} {k2} (rs :: [k1]) (ss :: [k1]) (f :: k2 -> Type) record (is :: [Nat]). (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 :: forall {u} (ss :: [u]) (rs :: [u]) (f :: u -> Type). (RecApplicative ss, RMap rs, rs ⊆ ss) => Rec f rs -> Rec (Maybe :. f) ss Source #
type REquivalent (rs :: [k]) (ss :: [k]) (is :: [Nat]) (js :: [Nat]) = (RSubset rs ss is, RSubset ss rs js) Source #
Two record types are equivalent when they are subtypes of each other.
type (∈) (r :: k) (rs :: [k]) = RElem r rs (RIndex r rs) Source #
A shorthand for RElem which supplies its index.
type (⊆) (rs :: [k]) (ss :: [k]) = RSubset rs ss (RImage rs ss) Source #
A shorthand for RSubset which supplies its image.
type (≅) (rs :: [k]) (ss :: [k]) = REquivalent rs ss (RImage rs ss) (RImage ss rs) Source #
A shorthand for REquivalent which supplies its images.