On Thu, Aug 6, 2020 at 7:30 PM <[email protected]> wrote: > > having fun with generics I stumbled upon this failure: > https://go2goplay.golang.org/p/Dc3tWrd6RzQ > > Bryan C. Mills helped me to fix it by forcing the type at the call point. > (the comment in the code) > > Forcing a type on a var you just declared is a little bit troublesome in this > case, but it could be more painful for other cases. > > Is that something that could be improved?
At first glance I don't think that would be a good idea. You want to infer the type argument to Printer[T] from the type printer[string]. But printer[string] is a struct and Printer[T] is an interface. We would have to take printer[string], look at the methods, compare them to the methods of Printer[T], and infer T from the method signatures. That is a lot of steps. Although I think we are going to make type inference more powerful, I think it's important that it always be simple and predictable for readers of the code. Inferring an interface type argument based on method types seems to me to be rather subtle. 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcW3HbFdtW2LWgjNXR6wmPckAB_B%2BiqB6uKXo%3D9F4R%2B%3DRQ%40mail.gmail.com.
