optics-dev / Monocly

Optics experimentation for Dotty
MIT License
32 stars 5 forks source link

GenLens 2.0 #10

Closed yilinwei closed 4 years ago

yilinwei commented 4 years ago

I'd like to finish #8 before finishing this, because unfortunately, we need to be a little more involved in getting the macro to work than I'd like in dotty.

The composeIso is there just because I couldn't work out how to get >>> working properly because you need to select the correct overload and it really doesn't like it. The crux of the issues is because it's really frustrating because the macro code is typed... but we can't express the types easily in the code since the types are not reflected not properly concrete. We can absolutely do this, but I don't want to put in more work until #8 is done and dusted.

At any rate, the crux of this idea is this:

  1. We have a dsl trait with phantom implementations ? in this case is meant to support an arbitrary error type provided it can go to an Either[E, A]. The phantom trait expects the user to then compose on A instead.
  2. We have specific macros like before such as GenLens. The Focus macro actually expands the GenLens macro inside of it multiple times with the correct type and a synthesized lambda!
  3. The macro strips out the ? at the moment and pipes it through the Iso. it should also lift the error type, but I need to work out how that looks in the hierarchy.

My intention is for the extension trait to have ? like rust's result, at/index self explanatory (we could also override get/apply, if it's more natural) and * for traversing (previously each).

Pinging @kenbot for any thoughts.