selda
selda copied to clipboard
Indexable for (:*:)
Inductively defined tuples can have lenses like normal tuples.
instance Field1 (a :*: b) (a' :*: b) a a' where
_1 k ~(a :*: b) = indexed k (0 :: Int) a <&> \a' -> (a' :*: b)
result :: String :*: Int
result = someTuple & _1 .~ "wat"
where
someTuple = ("foo" :*: 0)
-- > result
-- > "wat" :*: 0
These would be nice to have for updates. But, unless we want to depend on lens, unsure how to make instances w/o introducing orphans. Of course, we could ignore the warnings.
An alternative would be to have selector
return lenses, and have Selda
implement minimal lens functionality.
The update selectors from last night do more or less this, but I guess it would be nice to support proper lenses. I'm not particularly fond of the way lenses are often used to turn the simplest piece of code into opaque operator soup, but they are pretty nifty.
To keep dependencies to a minimum, perhaps microlens would be a good fit here? Possibly confining the lens stuff to a separate, exposed module and having a flag to disable them. I'd be happy to merge lens support, but I don't have the time or motivation to work on it myself at the moment.
Yes, microlens
might be worth it. This issue was mostly created to address the perceived lack of update selectors. I'd say we could backlog this issue, for now.