package main
import (
"fmt"
"reflect"
)
import "
golang.org/x/exp/constraints"
// Double returns a new slice that contains all the elements of s, doubled.
func Double[E constraints.Integer](s []E) []E {
r := make([]E, len(s))
for i, v := range s {
r[i] = v
}
return r
}
func main() {
// MySlice is a slice of ints.
type MySlice []int
// The type of V1 will be []int, not MySlice.
// Here we are using function argument type inference,
// but not constraint type inference.
var V1 = Double(MySlice{1})
fmt.Println(reflect.TypeOf(V1).String())
}
why use function argument type infer, and why function argument type infer int to []int?