4 ms·
Finally. Hope it gets approved. It's strange that they don't consider Print[T](x T) instead of Print[T any](t T). The "any" could just be omitted without loss
by alkonaut 6y ago
Finally. Hope it gets approved.
It's strange that they don't consider Print[T](x T) instead of Print[T any](t T). The "any" could just be omitted without loss of anything. Especially since repeated types with the same constraints indeed DO omit it! Print2[T1, T2 any]
- setr 6y agowell, it doesn't omit it; it just applies it to all preceding arguments that didn't have a qualifier, same as normal golang function arguments. It's still being explicit about the constraint being `any`
- uluyol 6y agoThe any is required to avoid a syntactic ambiguity. It was that or use the "type" keyword as in Print[type T] / Print[type T1, T2 Constraint]. The question of what the syntax should look like has been beaten to death.
- alkonaut 6y agoThere is ambiguity in Print[T](t T)? What different things could T represent there?
- ianlancetaylor 6y agoThere is no ambiguity there. The ambiguity arises for parameterized types. type A[T] int Is that a parameterized type named A with a type parameter T, or is it a definition of an array named A whose length is T? Separately, it's nice that type parameter lists use the same syntax as non-type parameter lists.