Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data SimpleRecordLens a b where
- SimpleRecordLens :: Lens' a b -> SimpleRecordLens a b
- data HKRecordLens d (f :: Type -> Type) tbl x where
- HKRecordLens :: Lens' (tbl f) (Interpret (d f) x) -> HKRecordLens d f tbl x
- data RegularRecordLens tbl f x where
- RegularRecordLens :: Lens' (tbl f) (f x) -> RegularRecordLens tbl f x
- lensesForSimpleRecord :: forall a. Generic a => Rep (SimpleRecordLens a) a
- lensesForHKRecord :: forall d tbl f. (Generic (tbl f), Generic (tbl Uninterpreted), HasNormalForm (d f) (tbl f) (tbl Uninterpreted)) => Proxy d -> Rep (HKRecordLens d f tbl) (tbl Uninterpreted)
- lensesForRegularRecord :: forall d tbl f. (Generic (tbl (RegularRecordLens tbl f)), Generic (tbl Uninterpreted), Generic (tbl f), HasNormalForm (d (RegularRecordLens tbl f)) (tbl (RegularRecordLens tbl f)) (tbl Uninterpreted), HasNormalForm (d f) (tbl f) (tbl Uninterpreted), Constraints (tbl Uninterpreted) (IsRegularField Uninterpreted), StandardInterpretation d (RegularRecordLens tbl f), StandardInterpretation d f) => Proxy d -> tbl (RegularRecordLens tbl f)
- data RegularField f x where
- RegularField :: RegularField f (f x)
- class IsRegularField f x where
- isRegularField :: Proxy (f x) -> RegularField f x
- data RepLens f a x where
- repLenses :: Generic a => Rep (RepLens f a) a
- genericLens :: Generic a => Lens' a (Rep I a)
- normalForm1Lens :: HasNormalForm (d f) (x f) (x Uninterpreted) => Proxy d -> Lens' (Rep I (x f)) (Rep (Interpret (d f)) (x Uninterpreted))
- interpretedLens :: Lens' (Interpret d x) (Interpreted d x)
- standardInterpretationLens :: forall d f x. StandardInterpretation d f => Proxy d -> Lens' (Interpret (d f) (Uninterpreted x)) (f x)
Lenses for records
data SimpleRecordLens a b where Source #
SimpleRecordLens :: Lens' a b -> SimpleRecordLens a b |
data HKRecordLens d (f :: Type -> Type) tbl x where Source #
Lens for higher-kinded record
See lensesForHKRecord
for details.
HKRecordLens :: Lens' (tbl f) (Interpret (d f) x) -> HKRecordLens d f tbl x |
data RegularRecordLens tbl f x where Source #
Lens into a regular record
RegularRecordLens :: Lens' (tbl f) (f x) -> RegularRecordLens tbl f x |
lensesForSimpleRecord :: forall a. Generic a => Rep (SimpleRecordLens a) a Source #
Construct lenses for each field in the record
NOTE: This is of limited use since we cannot pattern match on the resulting
Rep
in any meaningful way. It is possible to go through the SOP adapter,
but if we do, we incur quadratic cost again.
We can do better for higher-kinded records, and better still for regular
higher-kinded records. See lensesForHKRecord
and lensesForRegularRecord
.
lensesForHKRecord :: forall d tbl f. (Generic (tbl f), Generic (tbl Uninterpreted), HasNormalForm (d f) (tbl f) (tbl Uninterpreted)) => Proxy d -> Rep (HKRecordLens d f tbl) (tbl Uninterpreted) Source #
Lenses for higher-kinded records
NOTE: The lenses constructed by this function are primarily intended for
further processing, either by lensesForRegularRecord
or using application
specific logic. Details below.
Suppose we have a record tbl f
which is indexed by a functor f
, and we
want to construct lenses from tbl f
to each field in the record. Using the
Transform
infrastructure, we can construct a lens
tbl f ~~> Rep I (tbl f) ~~> Rep (Interpret (d f)) (tbl Uninterpreted)
Using repLenses
we can construct a lens of type
Rep (Interpret (d f)) (tbl Uninterpreted) ~~> Interpret (d f) x
for every field of type x
. Putting these two together gives us a lens
tbl f ~~> Interpret (d f) x
for every field in tbl Uninterpreted
. We cannot simplify this, because we
do not know anything about the shape of x
; specifically, it might not be
equal to Uninterpreted x'
for some x'
, and hence we cannot simplify the
target type of the lens. We can do better for records with regular fields;
see lensesForRegularRecord
.
lensesForRegularRecord :: forall d tbl f. (Generic (tbl (RegularRecordLens tbl f)), Generic (tbl Uninterpreted), Generic (tbl f), HasNormalForm (d (RegularRecordLens tbl f)) (tbl (RegularRecordLens tbl f)) (tbl Uninterpreted), HasNormalForm (d f) (tbl f) (tbl Uninterpreted), Constraints (tbl Uninterpreted) (IsRegularField Uninterpreted), StandardInterpretation d (RegularRecordLens tbl f), StandardInterpretation d f) => Proxy d -> tbl (RegularRecordLens tbl f) Source #
Lenses into higher-kinded records with regular fields
We can use lensesForHKRecord
to construct a Rep
of lenses into a higher-kinded
record. If in addition the record is regular, we can use the record type
itself to store all the lenses.
Regular records
data RegularField f x where Source #
Proof that x
is a regular field
See IsRegularField
RegularField :: RegularField f (f x) |
class IsRegularField f x where Source #
Regular record fields
For a higher-kinded record tbl f
, parameterized over some functor f
,
we say that the fields are regular iff every field has the form f x
for some x
.
isRegularField :: Proxy (f x) -> RegularField f x Source #
Instances
IsRegularField f (f x) Source # | |
Defined in Data.Record.Generic.Lens.Micro isRegularField :: Proxy (f (f x)) -> RegularField f (f x) Source # |
Lenses into Rep
General purpose lenses
normalForm1Lens :: HasNormalForm (d f) (x f) (x Uninterpreted) => Proxy d -> Lens' (Rep I (x f)) (Rep (Interpret (d f)) (x Uninterpreted)) Source #
interpretedLens :: Lens' (Interpret d x) (Interpreted d x) Source #
standardInterpretationLens :: forall d f x. StandardInterpretation d f => Proxy d -> Lens' (Interpret (d f) (Uninterpreted x)) (f x) Source #