I’m a little bit late to the party, but thank you so much for listening to us on this point
I hope we can settle all together on the minutiae of subtyping for these new exciting types !
(I’ll be happy even if the consensus doesn’t align with my opinions)
And thank you to the SIP committee and compiler team for their continued efforts in improving Scala !
It seems it’s not impossible to import named tuple members:
import language.experimental.namedTuples
def myMethod(tuple: (foo: Int, bar: String)): Unit =
import tuple.foo // Error: value foo is not a member of (foo: Int, bar: String)
println(foo)
myMethod((1, "one"))
I see no mention of imports in the SIP so I’m wondering if this is a design limitation or just a shortcoming of the current implementation?
Another question I have is whether synthesized TupledFunctions, e.g., obtained through f.tupled should use named tuple.
It doesn’t seem the case at the moment,
> scala --scalac-option -experimental
Welcome to Scala 3.6.2 (23, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala> import language.experimental.namedTuples
scala> def foo(x: Int, y: String): Unit = ???
def foo(x: Int, y: String): Unit
scala> foo.tupled
val res0: ((Int, String)) => Unit = scala.Function2$$Lambda/0x000079d96b59aa28@becb93a
I believe spec and implementation are in agreement here. foo is not a “member” of (foo: Int, bar: String). We can use the name foo to select the first element, but that’s not exactly the same thing. And since named imports need to select members, it follows that you can’t use them for a named tuple.
I wonder if NamedTuple could be made Selectable, and its Fields could be mapped to its own tuple type, and finally if names could be aliased to _1, _2, … through inlining.
That’s what i mean, to define default values, which can be omitted in name tuple literal constructors, however after rethink, maybe does not make sense for structural types like named tuples, though it does for named functions and nominal classes