Closed kdungs closed 1 year ago
Doesn't work because among other things https://go.dev/doc/faq#covariant_types.
//edit: The reason I still think this is more of a generics issue than a covariant types issue is that the following works:
func c[A any, B interface{ io.Reader }](f func(A) B, g func(io.Reader) string) func(A) string {
return func(a A) string {
return g(f(a))
}
}
but the rules for constraints currently prohibit using a type parameter inside interface {}
.
Collected examples from the discussion on the Gopher slack...
E.g.
doesn't compile because in
MapE
we haveB = *os.File
which implementsio.Reader
but is not identical to it...