Re: [go-nuts] Workaround for No parameterized methods in go generics draft

2021-01-14 Thread Ian Lance Taylor
On Thu, Jan 14, 2021 at 3:07 PM roger peppe wrote: > > FWIW I think that one possible approach to allowing methods (and potentially > function values) with type parameters might be to allow instantiating them > only with a limited set of "shapes" of data (for example, only pointer-like >

Re: [go-nuts] Workaround for No parameterized methods in go generics draft

2021-01-14 Thread roger peppe
FWIW I think that one possible approach to allowing methods (and potentially function values) with type parameters might be to allow instantiating them only with a limited set of "shapes" of data (for example, only pointer-like types). Then I think there's the possibility that the method or

Re: [go-nuts] Workaround for No parameterized methods in go generics draft

2021-01-14 Thread Marcus Manning
On 1/14/21 7:59 PM, Ian Lance Taylor wrote: On Thu, Jan 14, 2021 at 4:33 AM Marcus Manning 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.

Re: [go-nuts] Workaround for No parameterized methods in go generics draft

2021-01-14 Thread Ian Lance Taylor
On Thu, Jan 14, 2021 at 12:07 PM Marcus Manning wrote: > > On 1/14/21 7:59 PM, Ian Lance Taylor wrote: > > On Thu, Jan 14, 2021 at 4:33 AM Marcus Manning wrote: > >> Hmm..., then we should appreciate the alternative to generate a hidden > >> instance parameter for each instantiated type in the

Re: [go-nuts] Workaround for No parameterized methods in go generics draft

2021-01-14 Thread Ian Lance Taylor
On Thu, Jan 14, 2021 at 4:33 AM Marcus Manning 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

Re: [go-nuts] Workaround for No parameterized methods in go generics draft

2021-01-14 Thread Marcus Manning
On 1/14/21 1:49 PM, roger peppe wrote: This code seems corrupted (no newlines) and incomplete. It's hard to understand what your question is about without seeing the motivational code. I hate mailing lists for exactly this reason. Here is the code again: ``` package p1 // S is a type

Re: [go-nuts] Workaround for No parameterized methods in go generics draft

2021-01-14 Thread roger peppe
On Wed, 13 Jan 2021 at 20:38, Marcus Manning wrote: > > Regarding the the section of No parameterized methods in go generics > draft: > > package p1 // S is a type with a parameterized method Identity. type S > struct{} // Identity is a simple identity method that works for any type. > func (S)

Re: [go-nuts] Workaround for No parameterized methods in go generics draft

2021-01-14 Thread Marcus Manning
On 1/13/21 11:37 PM, Ian Lance Taylor wrote: On Wed, Jan 13, 2021 at 12:39 PM Marcus Manning wrote: Does reflection support generic instantiation? No. In the current proposal, generic functions and types are not visible at run time. Only instantiated functions and types are visible. So

Re: [go-nuts] Workaround for No parameterized methods in go generics draft

2021-01-13 Thread Ian Lance Taylor
On Wed, Jan 13, 2021 at 12:39 PM Marcus Manning wrote: > > Does reflection support generic instantiation? No. In the current proposal, generic functions and types are not visible at run time. Only instantiated functions and types are visible. So there is no way to even name a generic

[go-nuts] Workaround for No parameterized methods in go generics draft

2021-01-13 Thread Marcus Manning
Regarding the the section of No parameterized methods in go generics draft: package p1 // S is a type with a parameterized method Identity. type S struct{} // Identity is a simple identity method that works for any type. func (S) Identity[T any](v T) T { return v } package p2 // HasIdentity is