selda icon indicating copy to clipboard operation
selda copied to clipboard

Indexable for (:*:)

Open dmjio opened this issue 7 years ago • 2 comments

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.

dmjio avatar Apr 23 '17 05:04 dmjio

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.

valderman avatar Apr 24 '17 11:04 valderman

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.

dmjio avatar Apr 26 '17 01:04 dmjio