Thanks for your input. Clearly it's not the best example, but it surprised me. With your explanation, I get it. And also, reading my code again, it is confusing. I always thought that Go could benefit from generics, but clearly, I want to also avoid template meta programming, because it is clearly not fun to read. And even for this simple example, it takes a few readings to get.
Le vendredi 7 août 2020 18:32:42 UTC+2, Ian Lance Taylor a écrit : > > On Thu, Aug 6, 2020 at 7:30 PM <dol...@gmail.com <javascript:>> 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 golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/d00b1b19-0ff1-4a19-a380-a8a2d0f34c67o%40googlegroups.com.