There’s so much I’m liking about Scala 3 (the Optional Braces feature most of all, to my surprise) but I’m a little concerned that one “unofficial” feature of Scala 2 - Tagged Types - is missing, that is more important than it superficially appears.
There are a few versions of Tagged Types around but I’ve tended to use the Shapeless one.
What tagged types provide in Scala2 is “Poor Man’s Refinement Types” without introducing boxing for primitives (fwiw “Poor Man” here riffs on this landmark talk early in Scala’s history).
There’s also the excellent Refined library but IIUC that does induce boxing which is problematic in performance-sensitive or numerical code.
Refinement types are super useful to follow the statically-typed discipline to its logical conclusion, because they let you attach additional info about a value to its type, without changing its runtime representation.
The everyday use case is just qualifying the range of an
Int. Just because the JVM offers signed 32bit slots at machine layer, doesn’t mean every integer in our systems is sensibly defined as +/-2billion. It’s crucial for correct software to be able to declare, in types, that a value should be positive, or non-zero, or within some arbitrary range.
Some officially blessed means of expressing refined types in Scala3 is needed, without having to worry about impacts on performance or memory consumption.
Dedicated language-level support would of course be welcome, but alternatively, a tag-based mechanism could be made to serve. My understanding is that Scala2-style type tags don’t work in Scala 3.