func foo(arg0 int, argN ...string) string // SIGNATURE
foo(1, "a", "b", "c") // OK
foo(1, []string{"a", "b", "c"}...) // OK
foo(1, "a", []string{"b", "c"}...) // NOT OK
Just curious about these language decisions. Would appreciate some insight?
- The compiler will happily promote a type to an interface when necessary - but not for arrays. Tell me if I am wrong, but interfaces seem to get used a lot for rudimentary polymorphism (i.e. to accept polymorphic types with the same interface). It seems natural to want to extend this to arrays of such types. But the compiler won't promote the entire array of types to interfaces. Any reason why it will do a lone type, and not an array of types?
- A variadic function, for a type marked with "...", will accept (a) zero or more arguments of that type, or (b) a slice of that type - but not a mix of the two. I suppose there is a good reason for this. I'd like to know.
func foo(arg0 int, argN ...string) string // SIGNATURE
foo(1, "a", "b", "c") // OK
foo(1, []string{"a", "b", "c"}...) // OK
foo(1, "a", []string{"b", "c"}...) // NOT OK