Instead of doing the implicit conversion to the interface, why not relax the constraint and allow anything that implements the interface?
On Wednesday, June 17, 2020 at 1:37:35 AM UTC-7, David Anderson wrote: > > The non-generic form _only_ accepts an argument of type []Stringer. If you > have a []Foo, where Foo implements Stringer, that's not good enough. You > will have to construct a []Stringer explicitly, and copy each Foo into that > []Stringer. This is a fairly common gotcha with Go, where folks expect the > implicit conversion to happen. > > OTOH, the generic form will accept []Foo directly, since Foo satisfies the > Stringer constraint. > > - Dave > > On Wed, Jun 17, 2020 at 1:20 AM Christophe Meessen <christop...@gmail.com > <javascript:>> wrote: > >> Reading the document "Type parameters - Draft desing" of June 16, 2020 ( >> https://go.googlesource.com/proposal/+/refs/heads/master/design/go2draft-type-parameters.md), >> >> I wonder if these two following function definitions are not equivalent and >> thus interchangeable >> >> func Stringify(type T Stringer)(s []T) (ret []string) >> >> func Stringify(s []Stringer) (ret []string) >> >> If the constrain is an interface, wouldn’t it be the same as to use the >> interface as type ? How would it be different ? >> >> -- >> 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 golan...@googlegroups.com <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/golang-nuts/3b758827-2d14-4769-bf94-95cf60a06b1bo%40googlegroups.com >> >> <https://groups.google.com/d/msgid/golang-nuts/3b758827-2d14-4769-bf94-95cf60a06b1bo%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > On Wednesday, June 17, 2020 at 1:37:35 AM UTC-7, David Anderson wrote: > > The non-generic form _only_ accepts an argument of type []Stringer. If you > have a []Foo, where Foo implements Stringer, that's not good enough. You > will have to construct a []Stringer explicitly, and copy each Foo into that > []Stringer. This is a fairly common gotcha with Go, where folks expect the > implicit conversion to happen. > > OTOH, the generic form will accept []Foo directly, since Foo satisfies the > Stringer constraint. > > - Dave > > On Wed, Jun 17, 2020 at 1:20 AM Christophe Meessen <christop...@gmail.com > <javascript:>> wrote: > >> Reading the document "Type parameters - Draft desing" of June 16, 2020 ( >> https://go.googlesource.com/proposal/+/refs/heads/master/design/go2draft-type-parameters.md), >> >> I wonder if these two following function definitions are not equivalent and >> thus interchangeable >> >> func Stringify(type T Stringer)(s []T) (ret []string) >> >> func Stringify(s []Stringer) (ret []string) >> >> If the constrain is an interface, wouldn’t it be the same as to use the >> interface as type ? How would it be different ? >> >> -- >> 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 golan...@googlegroups.com <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/golang-nuts/3b758827-2d14-4769-bf94-95cf60a06b1bo%40googlegroups.com >> >> <https://groups.google.com/d/msgid/golang-nuts/3b758827-2d14-4769-bf94-95cf60a06b1bo%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > On Wednesday, June 17, 2020 at 1:37:35 AM UTC-7, David Anderson wrote: > > The non-generic form _only_ accepts an argument of type []Stringer. If you > have a []Foo, where Foo implements Stringer, that's not good enough. You > will have to construct a []Stringer explicitly, and copy each Foo into that > []Stringer. This is a fairly common gotcha with Go, where folks expect the > implicit conversion to happen. > > OTOH, the generic form will accept []Foo directly, since Foo satisfies the > Stringer constraint. > > - Dave > > On Wed, Jun 17, 2020 at 1:20 AM Christophe Meessen <christop...@gmail.com > <javascript:>> wrote: > >> Reading the document "Type parameters - Draft desing" of June 16, 2020 ( >> https://go.googlesource.com/proposal/+/refs/heads/master/design/go2draft-type-parameters.md), >> >> I wonder if these two following function definitions are not equivalent and >> thus interchangeable >> >> func Stringify(type T Stringer)(s []T) (ret []string) >> >> func Stringify(s []Stringer) (ret []string) >> >> If the constrain is an interface, wouldn’t it be the same as to use the >> interface as type ? How would it be different ? >> >> -- >> 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 golan...@googlegroups.com <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/golang-nuts/3b758827-2d14-4769-bf94-95cf60a06b1bo%40googlegroups.com >> >> <https://groups.google.com/d/msgid/golang-nuts/3b758827-2d14-4769-bf94-95cf60a06b1bo%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/4ad607e5-8ebc-4143-afd0-d51eeafea164o%40googlegroups.com.