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...@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.
type Ordered interface { type int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, uintptr, float32, float64, string }
type Ordered interface type { int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64,
byte, rune, uintptr, float32, float64, string, }
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAMx%2Br7Vc9pLY63qJg1ek4ZrYq8YMyJFOLwzN5aLA6T8nho16Ww%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAF9DLCm%3D0DSjRk2quhh%3D3L_eUH9%2BuxPXp6-8mzh%3DjZ0csy9rwQ%40mail.gmail.com.
The reason why implicit conversions from []Foo to []Stringer isn't supported is because Foo and Stringer have different in-memory representations. Converting from a slice of one to a slice of another would be more expensive than one would expect an implicit conversion to be. At least, this is my understanding as to why.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAA%3DXfu1_0stPaP0U%3Dv91%3DWcyvRiWO0Pg12cKmbFYbapq%2BKir2w%40mail.gmail.com.
Oh, it was a FAQ haha sorry about that and thanks Tyler and Ian :D
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAF9DLC%3DuAUJ3R8%3Dt%3DakiAiG-JPaxvkju7T%3DeU9saEirbOy8Z%3DA%40mail.gmail.com.
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> 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 interchangeablefunc 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/3b758827-2d14-4769-bf94-95cf60a06b1bo%40googlegroups.com.
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> 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 interchangeablefunc 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/3b758827-2d14-4769-bf94-95cf60a06b1bo%40googlegroups.com.
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> 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 interchangeablefunc 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.