At a glance, this feels to me like it is more complicated than the current
generics proposal. That said, it also seems very original so I have to give
credit there.

This proposal seems to put the responsibility for monomorphizing generic
code onto the programmer. I'm not sure why it would be simpler than
monomorphizing generic functions directly, which we can do today. Although
I guess under this proposal all the monomorphized versions would be able to
share similar function signatures and we can't do that today.

I do worry that in case you have two generic parameters, this proposal
would seem to require NxM cases to be explicitly written out. That feels
like a lot of work as compared to the current proposal, in which the
compiler can inspect the callsites and automatically generate only the
binary code needed to satisfy the types in use.


On Thu, Dec 31, 2020, 12:37 PM 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,
>
> --
> Wojciech S. Czarnecki
>  << ^oo^ >> OHIR-RIPE
>
> --
> 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/20201231193635.0d27177a%40xmint
> .
>

-- 
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/CALJzkY9EhOqhLYvXm2f7UV4WhQJWDBPB2O4PfbyYSTniP%2BqMRg%40mail.gmail.com.

Reply via email to