On Sun, Apr 4, 2021 at 2:18 PM K. Alex Mills <k.alex.mi...@gmail.com> wrote:
> This seems like a welcome change and leaves the door open for the future > inclusion of type unions. Nicely done! > > Regarding this approximation operator, I have a question about the > intended meaning of: > > ~struct{ > F int > A string > } > > Would this match the following types? > > type A struct{ > F int > A string > } > Yes. > > type B struct{ > A string > F int > } > No. The underlying types must be identical <https://golang.org/ref/spec#Type_identity>: Two struct types are identical if they have the same sequence of fields, > and if corresponding fields have the same names, and identical types, and > identical tags. The order must match. A good litmus test is that if A's type is a defined type and B's type isn't, then B is assignable <https://golang.org/ref/spec#Assignability> to A, if they have identical underlying types. You can test this like this playground snippet <https://play.golang.org/p/cqeLv9nlHSn>. type C struct{ > X int > Y string > } > No, fields must be named the same. type D struct{ > F int > A string > B float > } > No, numbers of fields must be the same. My guess is that we're talking about an exact type match, so it would > definitely match A, I'm not sure about B without checking the compiler, and > I don't think it would match either C or D under the current proposal. > > I think it could potentially be useful to have this approximation operator > match type D, although that would require modifying the proposal to specify > some notion of "field sets", which seems like it could be a departure from > how Go currently views structs and therefore may introduce further > complications I am not aware of. Just curious if it's already been > considered and discarded. > > Thanks! > > On Thu, Apr 1, 2021, 5:59 PM Ian Lance Taylor <i...@golang.org> wrote: > >> We've just posted a potential update to the generics proposal at >> https://golang.org/issue/45346. This clarifies and simplifies the >> type lists that appear in interfaces, and let's us drop the "type" >> keyword used to mark such lists. >> >> 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+unsubscr...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/golang-nuts/CAOyqgcVEx53D7YmFRBe43_jcrVSt%2BPbDEYjc4EZnpe1YyBNAtg%40mail.gmail.com >> . >> > -- > 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/CALJzkY9oy9m630f_04EZz9BXeS085nG6b04EoSdp%3DsnR%2BA4_Vg%40mail.gmail.com > <https://groups.google.com/d/msgid/golang-nuts/CALJzkY9oy9m630f_04EZz9BXeS085nG6b04EoSdp%3DsnR%2BA4_Vg%40mail.gmail.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/CAEkBMfEFkQffQMUStgUtHP-A-_7Y1%3DgGN%3DeCi%3DQBDJM12Zo3Lw%40mail.gmail.com.