Closed julien-truffaut closed 3 years ago
There is an issue with overriding modifyF
Please do! 🙏
I think inheritance "tells the truth" about the relationship between the optics. As long as it doesn't do anything crazy for type inference or variance or whatever, I think it's a good idea.
You shouldn't weigh this heavily at all, I signed up for difficulty, but it will certainly make Monocle 3 macro-writing slightly more convenient.
I made some progress but unfortunately it doesn't look good.
As @tpolecat told me in gitter, Scala doesn't accept narrowing on inputs https://gitter.im/scala/scala?at=602fd83b9ba13e72e43d7ea1
We could get around that by defining two version of modifyF
for Lens
, one that takes a Functor
and one that takes an Applicative
and write one in terms of the other. This trick works if all the arguments are within the same parentheses but it doesn't work if they are split over several parameterer lists :(
Since there is only one method affected: modifyF
, maybe we could consider tto remove the overload and do:
trait Lens[S, T, A, B] {
def foo[F[_]: Functor ](update: A => F[B])(from: S): F[T]
def bar[F[_]: Applicative](update: A => F[B])(from: S): F[T]
}
but I am not sure how to call foo
and bar
modifyF -> Functor
and modifyA -> Applicative
Inheritance is overloading some methods because they have slightly different shape for optics with 2 or 4 type parameters, see https://github.com/optics-dev/Monocle/pull/1082.
Implemented in #1088
Currently, Optics have a few methods
asX
, e.g.asTraverse
,asOptional
onLens
to "upcast" optics.Instead, we could introduce inheritance between optics, e.g.
Then we can deprecate all the
asX
methods.