Re: [go-nuts] Generics and constraints question

2021-01-05 Thread Brian Candler
On Tuesday, 5 January 2021 at 20:27:57 UTC rog wrote: > You can do this with type-list interfaces: > https://go2goplay.golang.org/p/wfHnVHOMcyK > > This is one of the harder parts of the proposal to understand IMHO, but > perhaps it will become easier with familiarity. > Thank you! -- You re

Re: [go-nuts] Generics and constraints question

2021-01-05 Thread Ian Lance Taylor
This definitely needs a better error message. Ian On Tue, Jan 5, 2021 at 12:27 PM roger peppe wrote: > > You can do this with type-list interfaces: > https://go2goplay.golang.org/p/wfHnVHOMcyK > > This is one of the harder parts of the proposal to understand IMHO, but > perhaps it will become

Re: [go-nuts] Generics and constraints question

2021-01-05 Thread roger peppe
You can do this with type-list interfaces: https://go2goplay.golang.org/p/wfHnVHOMcyK This is one of the harder parts of the proposal to understand IMHO, but perhaps it will become easier with familiarity. On Tue, 5 Jan 2021, 17:32 Brian Candler, wrote: > Question: how to make a generic functio

[go-nuts] Generics and constraints question

2021-01-05 Thread Brian Candler
Question: how to make a generic function which takes a type T where the constraint is "*T satisfies a given interface"? func (m *MyMap[KT, VT]) init() { m.data = make(map[KT]VT) } type Initializer interface { init() } func mynew[T Initializer]() *T { t := new(T) t.init() return t } /*