>
> Competition is good, only when the Go team feels the heat of competition 
> they will think about working on their type system seriously.


I think everybody here is aware that some people really want generics and 
that generics would probably be useful for everybody. Instead of restating 
that why not share what you think about this version of Go generics?

If you have other ideas for generics please read the discussion thoroughly 
and add your thoughts: https://github.com/golang/go/issues/15292

Go is hot right now just like Rails or Node.js used to be hot.


I think everybody here likes Go and would like to keep it hot. Obviously 
adding a bad feature would hurt not just popular perception but also people 
who write a lot of Go.

Anyway, the two cases I’ve been looking at are a generic unordered set type 
and a collection pick function without adding a new built-in. Here’s those 
with that first data case.

type set []T

func (s *set) append(t T) { s = append(set, t) }

On the surface this looks straightforward here for the compiler since 
append is already generic, but how would you make a set?

a := set<string>{“hello,”, “world!”}

a := set{“hello,”, “world!”}

// the compiler says mismatched types?
a := set{“hello”, 1, map[string]string{}}

// can the compiler check for this kind of thing in all cases?
a := set{}
a = a.append(“hello”)
a = a.append(1)

// pseudorandomly pick n elements from collection T 
pick(t T, n uint) []U

How to constrain T to collection types only?

Thanks,
Matt

On Saturday, February 17, 2018 at 3:18:17 AM UTC-6, dc0d wrote:
>
> Indeed it's a form of package/block level code-specialization, so called 
> generics.
>
> There is a proposal for package level generics by me too.
>
> My main concern here was to have this feature without invalidating current 
> Go code bases, by allowing the rebinding of Type Aliases 
> <https://docs.google.com/document/d/1vrAy9gMpMoS3uaVphB32uVXX4pi-HnNjkMEgyAHX4N4/edit#heading=h.3hz723usuzv2>
> .
>
> For block level generics - as suggested at the first post - there might be 
> some substantial changes needed to be made to the language - except for the 
> last form: Interface Receivers with Original Types, which allows to not 
> touch current Go code bases.
>
> All in all Go is a fantastic tool with it's own merits.
>
> On Saturday, February 17, 2018 at 6:25:58 AM UTC+3:30, Mandolyte wrote:
>>
>> I think this falls into a variation of package level generics.
>>
>> Look over the document below and see if there is any changes you would 
>> recommend.
>>
>>
>> https://docs.google.com/document/d/1vrAy9gMpMoS3uaVphB32uVXX4pi-HnNjkMEgyAHX4N4/edit?usp=drivesdk
>>
>> Thanks for sharing!
>>
>>

-- 
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.

Reply via email to