Pitch - Function-style generic type signatures

I'm sure that this has been discussed before in some distant past, but I've browsed the forum regularly for a long time and haven't seen much about it, plus I think there's some new context these days specifically with regard to variadic generics.

Is the idea entertained or laughably unfeasible to give the full (or nearly full?) power of function signatures to generic type signatures?

struct Either <_ First, or Second> {

}
let usage: Either<Int, or: Bool>

Similarly to subscript parameters, if only a single name is provided for a generic parameter then it is treated as having no external argument label, but also it is valid to explicitly use an underscore to mean "no external argument label", as I did in the example above. This means that it isn't source breaking (I think) because, all current generic signatures continue to mean the same thing, but a whole class of new and more expressive ones are enabled. I read somewhere in one of the variadic generics posts that some special considerations were having to be made due to generic types' inability to have argument labels which delimit generic parameters. @hborla @Slava_Pestov Would this change I'm talking about make anything simpler in the world of variadic generics? Or perhaps it would complicate the matter even further?

13 Likes

Labels for type parameters. Hmm….

I tend to think that if you have a whole lot of generic type parameters, you’ve probably gone down a bad path, and likely should be using associated types instead (which prevent the combinatorial growth of type params when composing types etc)…

…but your example is compelling! Labeled type parameters certainly could improve readability in some cases, and it does seem like the introduction of variadic generics is only going to increase those cases.