Constraint type inference is useful when a function wants to have a type name for an element of some other type parameter, or when a function wants to apply a constraint to a type that is based on some other type parameter.
Constraint type inference can only infer types if some type parameter has a constraint that has a type list with exactly one type in it.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAJhgaciL%3D0p3rwMOmXW3oxNFhKVWFa6bT6-SsBi-E5iaeFxYqQ%40mail.gmail.com.
If I understand you correctly, we changed that when we added the
constraint type inference section. See the updated
https://go.googlesource.com/proposal/+/refs/heads/master/design/go2draft-type-parameters.md#type-inference
section.
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcVvLvuAVy%3DWVA2n4wCcpEKNfbxTN-d_K%3Dz8kz1oiK9Z3g%40mail.gmail.com.
If I have
func F[type E interface{}, S constraints.Slice[E]]() S
are the following equivalent:
F[int, []int]
F[int]
F[[]int]
or are only 2 of the 3 permissible? Does that change if I swap the
type parameters?
"When only some type arguments are passed, they are the arguments for the first type parameters in the list."
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CANG3jXJ60zyaBsYmvOSJdgX3J%3DaB0_Taz2SnuM31Rg3N0bx8mw%40mail.gmail.com.
Ian
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAJhgacjPfoUp%2Bkhb4csuF%2Bz%3DTEWchZuSri94yTP4%2BtRvtnK5Ng%40mail.gmail.com.
I think that it's really crucial for type inference rules to be as simple and clear as possible. There must never be any confusion as to what an inferred type might be. In complicated cases, it's fine to explicitly list the type arguments. In fact, it's more than fine: it's desirable.