In the first example, the inferred type is `float64`, so the signature of
the function is `func do([]float64)`. You can obviously pass a `[]float64`
to it.
If X is a concrete (i.e. non-interface) type, then `func F[T X]()` is
syntactic sugar for `func F[T interface{ X }]()`, which is a constraint
that has a single union-element and that union-element lists a single type.
So `func do[T []any](v T)` allows to instantiate the function with only a
single type: `[]any`. Because `[]any` is not an interface type.
And you can't pass a `[]float64` to a function accepting an `[]any`,
because slices are invariant.
The two signatures really mean completely different things. Writing `func
do[S []E, E any]` really means "S has type []E, where E can be any type",
which is a very different thing from saying "it's a slice of the specific
type any".

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAEkBMfEBCWxtC6ybBBU1bfJP0%2BGpoS39eAbLyznzO%2BGU%3DfWa%3DA%40mail.gmail.com.

Reply via email to