You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To use field tags to magic up type-changing lenses (somewhat like generic-lens), some changes would be required. Let's think about what the challenges are, and how they might be resolved
Field is a data family, so, for example, Field (a, b) and Field (c, d) are completely separate types.
Even if Field became a type family (of arity 1), we'd have no obvious way to relate, say, Fst :: Field (a, b) a with Fst :: Field (c, d) c.
Hrmph.
Maybe a mechanism like generic-lens is just better for editing records, and prarie is more for building them? I dunno.
The text was updated successfully, but these errors were encountered:
dataTa=T{x::a, y::Int}instanceRecord (Ta) wheredataField (Ta) twhereTX::Field (Ta) aTY::Field (Ta) Int
recordFieldLens =\caseTX-> lens x (\o n -> o { x = n })
TY-> lens y (\o n -> o { y = n })
tabulateRecordA f =T<$> f TX<*> f TY
recordFieldLabel =\caseTX->"TX"TY->"TY"classPolyLenstwherepolyLens:: (forallx.Field (tx) x) ->Lens (ta) (tb) abinstancePolyLensTwhere
polyLens =\caseTX-> lens x (\o n -> o { x = n }) ::Lens (Ta) (Tb) ab
But it kinda sucks that you need to opt-in to polyLens, and it's also parametric - same restriction as Functor.
It looks like I can write an instance for a tuple:
instance (Recorda, Recordb) =>Record (a, b) wheredataField (a, b) twhereFst::Fieldar->Field (a, b) rSnd::Fieldbr->Field (a, b) r
recordFieldLens =\caseFst f ->
_1 . recordFieldLens f
Snd f ->
_2 . recordFieldLens f
recordFieldLabel =\caseFst f ->"Fst "<> recordFieldLabel f
Snd f ->"Snd "<> recordFieldLabel f
tabulateRecordA fromField =
(,) <$> tabulateRecordA (fromField .Fst) <*> tabulateRecordA (fromField .Snd)
It does seem like prairie, especially via tabulateA, is really nice for constructing and doing metaprogramming over records, but the facilities just aren't quite there for more complicated modifications. generic-lens and especially the HasTyped stuff are really nice for that.
To use field tags to magic up type-changing lenses (somewhat like
generic-lens
), some changes would be required. Let's think about what the challenges are, and how they might be resolvedField
is a data family, so, for example,Field (a, b)
andField (c, d)
are completely separate types.Even if
Field
became a type family (of arity 1), we'd have no obvious way to relate, say,Fst :: Field (a, b) a
withFst :: Field (c, d) c
.Hrmph.
Maybe a mechanism like
generic-lens
is just better for editing records, andprarie
is more for building them? I dunno.The text was updated successfully, but these errors were encountered: