On 31-12-2020, Ian Lance Taylor wrote:
> On Thu, Dec 31, 2020 at 10:37 AM Wojciech S. Czarnecki <o...@fairbe.org> 
> wrote:
>>
>> I regard current Team's proposal a way better than the first iteration. But -
>> while I see a need for generic way to write common code, I also share
>> concerns about readability and future abuse of the materialized Go generics
>> being similar to "the other languages". I consciously did not patricipate in 
>> the
>> [Generics, please go 
>> away!](https://groups.google.com/g/golang-nuts/c/LEEuJPOg0oo)
>> bikeshed, but I would like to share an idea that may possibly reconcile both 
>> camps.
>>
>>        "Signature switch" - readable generic code preserving the Go way.
>>
>> Generic function declaration is 
>> https://golang.org/ref/spec#Function_declarations
>> with at least one type in the Signature given as the ascii character "+" 
>> followed
>> by single capital ascii letter, further reffered to as "TypeLetter"; and 
>> with a single,
>> non empty, signature switch present in the function body:
>>
>> func f (x +T) (r +R) {      // generic function
>>         switch func.(type) {      // Signature Switch here. Resolves at 
>> COMPILE TIME.
>>         case func(x int) (r int): // call-site signature to match
>>                 r = x/2                 // instantiated code, T and R are 
>> now ints
>>         }
>>         return r
>> }
>>
>> More to read at: https://play.golang.org/p/Q1ry4KPoOOJ
>>
>> Hope this helps,
>
> Thanks, it's an interesting idea.
>
> That said, one of the minimal requirements that I think applies to any
> generics proposal is the ability to write a compile-time-type-safe
> container, such as a concurrent hash map.  

I understand in his description that it's type safe at compile time.

>>         switch func.(type) {      // Signature Switch here. Resolves at 
>> COMPILE TIME.
                                                               
^^^^^^^^^^^^^^^^^^^^^^^^^

I like it this way, it's look like closure and immediatly understandable
for go users (maybe func f( x[T]) (r [R]) ?)

-- 
wilk

-- 
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/rsn1av%248fa%241%40ciao.gmane.io.

Reply via email to