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 <
christophe.mees...@gmail.com> 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 golang-nuts+unsubscr...@googlegroups.com.
> 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/CAMx%2Br7Vc9pLY63qJg1ek4ZrYq8YMyJFOLwzN5aLA6T8nho16Ww%40mail.gmail.com.

Reply via email to