I’ve noticed that using NamedTuple requires explicitly referencing NamedTuple.NamedTuple in type constraints, which feels a bit verbose compared to the simpler Tuple.
For example:
def f[T <: Tuple](t: T): Unit = ??? // Simple and concise for regular tuples
def g[N <: NamedTuple.NamedTuple](n: N): Unit = ??? // More verbose for named tuples
I understand that NamedTuple is defined in the scala.NamedTuple module, and I can simplify the syntax by importing scala.NamedTuple.* or defining a type alias like type NT = NamedTuple.NamedTuple. However, this still feels less ergonomic than the default availability of Tuple.
My questions are:
-
What are the design reasons behind not importing NamedTuple.NamedTuple by default in Scala 3.7? For instance, is this to avoid namespace pollution, ensure explicit intent, or address potential type inference issues?
-
Are there plans to introduce a shorter alias (e.g., scala.NTuple) or make NamedTuple more seamlessly integrated into the language, similar to Tuple?
-
Are there recommended best practices for working with NamedTuple to reduce verbosity while maintaining clarity?
-
(Another question) Why not define
opaque type AnyNamedTuple <: Tuple = Tuple