3 ms·
> You can tell just from the type signature that that is a useless use of generics. It's… not, though? In my understanding Go generics are reified, so this av
by masklinn 5y ago
> You can tell just from the type signature that that is a useless use of generics.
It's… not, though?
In my understanding Go generics are reified, so this avoids boxing the reader, and should allow for static dispatch.
How useful that is can be debated, but that's hardly useless.
- mseepgood 5y agoThe design does not require a specific implementation strategy (monomorphization, boxing or other approaches are possible). It can change from Go implementation to Go implementation and from Go version to Go version.
- jerf 5y agoIt works the other way too; the implementation is not obligated to pass an interface value to a function. The interface can be monomorphized too, if the compiler saw fit, and it would be a compliant implementation. At the language level, it's a useless use of generics. Even if generics someday used a monomorphic implementation, the compiler would be able to translate those two things back and forth trivially.