On Tue, Jul 30, 2019 at 8:31 PM <alan.f...@gmail.com> wrote: > My suggestion was that you can't use a pointer type as a type parameter if > the latter is subject to a contract. >
I'm not sure I understand you. Wouldn't that preclude using a generic map with pointers as keys? > In the case you mention, the contract could be expressed as a disjunction > of value and pointer methods: > > contract stringer(T) { > T String() string, *T String() string > } > Currently, Disjunctions only apply to a single type. You can't form expressions like this. IMO that's a good restriction to maintain. Because the more powerful the contract language becomes, the harder it'll be to make it useful. > On the other hand and more generally, not knowing whether the type > parameter represented a pointer or a value might lead to some awkward > coding. For example, you wouldn't be able to de-reference the type argument > as it might not be a pointer. > If a generic function wants to de-reference an argument, it should specify that as a pointer: func f(type T) (p *T) This is the same as with slices, maps, channels, functions or any composite type - you can't express "type parameter T should be a slice of some kind", because you are instead expected to just specify []T if you want a slice. > > It's clearly an area where some more thought is needed as Ian intimated > earlier. > > Alan > > -- > 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/302c6d33-a8ea-4e8a-b02b-7cff1b3de1c5%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/302c6d33-a8ea-4e8a-b02b-7cff1b3de1c5%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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/CAEkBMfHPNF6n%2Bc3%2BipqO-nh1%3DeTLstoxnUS_UOKiHRaPX1Yoog%40mail.gmail.com.