Consider:
data T a b where
MkT :: a #-> b -> MkT a b
(what matters here is that the second field is unrestricted)
If I have a lens l2 into the second field, then I can actually set the value at l2 linearly (currently, set l2 :: b' -> T a b -> T b', no linearity anywhere).
In #79 , there was
set'' :: Optic_ (NonLinear.Kleisli (Control.Reader b)) a b s t -> b #-> s -> t
set'' (Optical l) b s = Control.runReader (NonLinear.runKleisli (l (NonLinear.Kleisli (const (Control.reader id)))) s) b
to this specific effect.
Unrestricted lenses
But what is the type of l2? Certainly it's not going to be Optic_ (NonLinear.Kleisli (Control.Reader b)), it doesn't compose with anything. A reasonable requirement for the type of l2 is that it is a super type of Lens.
We can probably work this out. In a sense T is the prototypical example. An unrestricted-field-lens should define an isomorphism between a type, and T x b for some x. We basically need a variant of
second :: a `arr` b -> (c,a) `arr` (c, b)
Replacing (,) with T (or something equivalent).
Something to this effect anyway. Maybe we can see it as two properties, one relating to the pair, and one to the unrestrictedness. So that we could deal with unrestricted fields in prisms and traversals as well.
Replace set?
What I'm sort of wondering too, is whether this set'' could subsume set some way. Probably not, to be honest. Though it's a bit sad to have two different set functions which do the same thing, just in slightly different circumstances.
Consider:
(what matters here is that the second field is unrestricted)
If I have a lens
l2into the second field, then I can actuallysetthe value atl2linearly (currently,set l2 :: b' -> T a b -> T b', no linearity anywhere).In #79 , there was
to this specific effect.
Unrestricted lenses
But what is the type of
l2? Certainly it's not going to beOptic_ (NonLinear.Kleisli (Control.Reader b)), it doesn't compose with anything. A reasonable requirement for the type ofl2is that it is a super type ofLens.We can probably work this out. In a sense
Tis the prototypical example. An unrestricted-field-lens should define an isomorphism between a type, andT x bfor somex. We basically need a variant ofReplacing
(,)withT(or something equivalent).Something to this effect anyway. Maybe we can see it as two properties, one relating to the pair, and one to the unrestrictedness. So that we could deal with unrestricted fields in prisms and traversals as well.
Replace
set?What I'm sort of wondering too, is whether this
set''could subsumesetsome way. Probably not, to be honest. Though it's a bit sad to have two differentsetfunctions which do the same thing, just in slightly different circumstances.