Hi all,
Yilin recently had an idea for a SIP proposal for Scala 3 that I think would benefit to Monocle, ZIO and probably the rest of the Scala ecosystem. It is quite a vague concept at the moment, but I thought it would be worth getting your inputs.
Problem: ZIO, fs2 and other libraries found out that a natural encoding in Scala relies on multiple type parameters with variance (I believe John called this effect rotation):
- ZIO[-R, +E, +A]
- fs2.Stream[F[_], +A]
- Optic[+E, -S, +T, +A, -B] or even more type parameters if include index optics
With this encoding, we can express the absence of error (E = Nothing), absence of effect (F = Nothing), absence of environment variables (R = Any) and all with perfect type inference. So it is a big win on all fronts except for function signatures and error messages. As we can end-up with an Optic[Nothing, User, User, String, String]
instead of Lens[User, String]
or ZIO[Any, Nothing, Int]
instead of UIO[A]
. Type aliases help a little bit, but they get often lost.
The proposal: Define a set of rules for the compiler to use the most "precise" type alias in type inference and error messages.
For example, the compiler could look inside of companion object for type aliases and try them in top-to-bottom order or something more efficient.