On Sun, Mar 20, 2022 at 12:20 PM xie cui <cuiwei...@gmail.com> wrote:

> why use function argument type infer, and why function argument type infer
> int to []int?
>

Because the signature says `[]E`. So, the inference tries to determine `E`,
infers it to be `int` and then substitutes that into the return type to
make it `[]int`. `MySlice` is assignable to `[]int`, as they have the same
underlying type and the latter is not a defined type. So, you can pass
`MySlice` to `Double[int]` just fine.

You have to actually mention a separate type for the compiler to emit one,
otherwise it will just do what it told you:
https://go.dev/play/p/l1ochwkavNN


> --
> 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/f102326a-5cf6-40dc-bd57-268016284aecn%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/f102326a-5cf6-40dc-bd57-268016284aecn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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/CAEkBMfFZ8gXfaYpxh_yLx37uG776_mfb_8z_Ag93CCMbJQ5w1A%40mail.gmail.com.

Reply via email to