I understand the reasons what it wasn't pursued further.
Did the authors investigate the possibility of declaring generic types on a package level instead of per type/function? Ie.
generic T {}
func Max(a, b T) T {}
func Min(a, b T) T {}
I wrote down an idea on this, that is admittingly a bit wild (or naive) or maybe impossible from a parsing perspective. But I'd like to validate the main idea behind it.
My whole attempt was based on the observation that most packages that will include generic functionality, will only really need one or maybe a couple of generic type constraints.
For example, if you look at a hypothetical statistics package, there will be many, many functions that compute stuff on slices of T, where T must be a number. So there will be many functions like:
type Number interface { // using currently proposed generics
type int, float64, // etc
}
func Average(type T Number)(values T...) T {} // using currently proposed generics
func Median(type T Number)(values T...) T {}
func Binonimal(type T Number)(values T...) T {}
// etc etc etc
My point is that the "(type T Number)" part in all the declarations / definitions become really redundant from a human perspective, just because a package will naturally (should?) only use 1 or at most a couple of generic types. That would make it, at least theoretically, possible to write something like
type Number interface {
int, float64, // etc
}
generic T Number
func Average(values T...) T {}
func Median((values T...) T {}
// etc
Coincidentally, the builtin language sort of uses this idea in its documentation.
Another (theoretic) possibility would be something like this:
generic T Number ( // analog to multiple const or var declarations
func Average(values T...) T {}
func Median((values T...) T {}
)
My question is: did the authors investigate something like this, or is it plainly impossible or undesired?