On Thu, Jan 14, 2021 at 12:07 PM Marcus Manning <icons...@gmail.com> wrote: > > On 1/14/21 7:59 PM, Ian Lance Taylor wrote: > > On Thu, Jan 14, 2021 at 4:33 AM Marcus Manning <icons...@gmail.com> wrote: > >> Hmm..., then we should appreciate the alternative to generate a hidden > >> instance parameter for each instantiated type in the function body. The > >> hidden parameters might need to be up-propagated. Further, using > >> reflection, these hidden parameters have to be optionals or include nil > >> as we don't know if instances for a type parameter are available: > > The current proposal tries pretty hard to avoid requiring a specific > > implementation strategy. > > > > Ian > > I don't know if this is really specific as it doesn't require that much > to a backend. Usually, this is how things work with generic > typeclasses/interfaces/traits/concepts/, you are required to provide > witness tables along with. > > But because the example uses reflection, it may be more valuable just to > store reified conformances like triples as RTTI: > > (type: p1.S,witness: p1.Identity[Int],interface: p2.HasIdentity[Int]) > //in a global table? > > Then we ask for example: reflection give me the witness for S regarding > HasIdentity //that would be idiomatic, I think. > > In think, if we could add such a functionality later without to break > existing code we're fine to implement generics without this feature, > otherwise we can't introduce the proposed functionality later.
What you are describing is basically how Go implements interface types. I don't understand how to tie this back to generics. In the current proposal, type parameters are a purely compile-time concept. A valid implementation would be full monomorphization aka stenciling of all type arguments, similar to the way that C++ templates work. 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/CAOyqgcVaNMdu38fAmUbQWhSXhYLgeKMNgTt9_fmaTxGQQqrUgw%40mail.gmail.com.