IMO,
If we mainly require literals for BigInt/BigDecimal,
then there is no need for the Generic Number Literals feature. Simply support the number tokens to end with #
to get either:
val bigOne: BigInt = 1#
val bigDecimalOne: BigDecimal = 1.0#
val bigBinary: BigInt = 0b0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010#
val bigHex: BigInt =
0x12345454365465765aba534bade873546548343535#
Instead of #
we can think of other endings. We need a single character that won’t look like a unit of measurement or size (e.g., W
looks like Watt, G
would look like Giga), and it cannot be B
for hexadecimal compatibility.
And if we really require generic literals,
then the current feature is not generic enough and is very limited in its application since it cannot interact well with extension methods and implicit conversions. String interpolation should be enough for such cases, but, if it’s still too verbose, then consider the sharp interpolation feature, instead.
So in summary, the currently generic number literals feature, IMO, is a half-measure that over-complicates the common cases and doesn’t handle the real generic ones. It should be dropped from the language.