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.  It should be possible to
declare a hash map that takes any comparable type as a key type, and
any type as a value type, and provide methods to insert and look up
values in the hash map.  It should be possible to use that hash map
safely without writing any type assertions that might fail at run
time.  I don't see how to do that with this suggestion.

Ian

-- 
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/CAOyqgcX%3DXmL3GeGKahHVYiLUF8snC0h4cm5R5Fs8H1xZLo6vdg%40mail.gmail.com.

Reply via email to