On Wed, Jan 20, 2021 at 2:08 AM Brian Candler <b.cand...@pobox.com> wrote: > > In the Generics proposal, type constraints (other than type lists) take the > form of interfaces. For example, a generic type T may be constrained with > interface C. > > Question: if a function takes type T, does that permit *both* values of > concrete types which implement C, *and* interface values which implement C? > Apparently it does: > https://go2goplay.golang.org/p/sVaW1YoXKf1 > > That, to me, is surprising at first. I write a generic function because I > want it to be expanded for different concrete types; but then I am surprised > to find it can also be used for dynamic runtime types.
I think that's a confusing way of describing what is happening. A generic function can only be instantiated for different concrete types. In many cases, an example of a concrete type that may be used is an interface type. It's true that the values of an interface type have a dynamic runtime type. But the interface type is still a concrete type. 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/CAOyqgcViNC1dV3W-b4Nu2N9Pupw4LvHgA9cOvUzxpaAf54MkWA%40mail.gmail.com.