It leads me to the second part of my issue. In the “proposed changes” thread above, the distinction is made between several patterns, among which is a enrichment pattern, now managed by extension methods, and a promotion (aka magnet) pattern, which will remain but restricted to a declarative basis with the into
keyword. Coming back to the BigInt
example, numeric promotion will have to be explicitly allowed in operator methods:
def +(that: into BigInt): BigInt = ???
But Scala 3 implicits improvement allows us to go further. Instead of a wrapper class, we could use a Numeric
typeclass instance for java.math.BigInteger
so as to enrich it with arithmeric operators as suggested in this thread. This could be a change of the standard library, once it is available again for updates. But the problem is with the interaction of enrichment and promotion. As seen above, the implicit conversion from Int
to BigInt
is found in BigInt
s implicit scope. But if instead we take BigInteger
with a typeclass enrichment, then there is no more implicit scope where to look for the conversion. This is a very concrete issue I am facing in my computer algebra project where I can easily have numeric promotion for operands on the right but not on the left:
val a = BigInteger("1") + 1 // works
val b = 1 + BigInteger("1") // no way
I would be very happy to find a solution to this problem.