Also, and I think this probably applies to the existing syntax in the design. This example seems like a pathological use of generics. What would be the advantage over just declaring the function takes a Stringer? Am I missing something (presumably this is potentially avoids the interface call allocation?). This is a good example of my gut feeling about generics, I realise they'll be valuable, but do they devalue interfaces? They do not seem like an orthogonal feature. Of the two, interfaces feel like they encourage me to write better structured code. This could also just be fear of change.
On Fri, 31 Aug 2018 at 14:34 'Axel Wagner' via golang-nuts < golang-nuts@googlegroups.com> wrote: > A contract can include multiple type parameters: > https://go.googlesource.com/proposal/+/master/design/go2draft-contracts.md#mutually-referential-type-parameters > AIUI your syntax can't cover that. And FWIW, I find the syntax of > contracts in the doc far less "magic" than yours, but YMMV of course. > > On Fri, Aug 31, 2018 at 6:43 AM Manlio Perillo <manlio.peri...@gmail.com> > wrote: > >> I just read the "official" proposal for Go2 generics and contracts. >> The current proposal makes the function syntax more complex, and the >> syntax for the contract is a bit magic. >> >> What about something like: >> >> >> type stringer template >> >> contract (x stringer) { >> var s string = x.String() >> } >> >> func Stringify(s []stringer) (ret []string) { >> for _, v := range s { >> ret = append(ret, v.String()) >> } >> return ret >> } >> >> instead of >> >> >> contract stringer(x T) { >> var s string = x.String() >> } >> >> func Stringify(type T stringer)(s []T) (ret []string) { >> for _, v := range s { >> ret = append(ret, v.String()) >> } >> return ret >> } >> >> >> Thanks >> Manlio >> >> -- >> 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. >> For more options, visit https://groups.google.com/d/optout. >> > -- > 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. > For more options, visit https://groups.google.com/d/optout. > -- 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. For more options, visit https://groups.google.com/d/optout.