On Wed, Oct 17, 2018 at 1:47 PM Andy Balholm <andybalh...@gmail.com> wrote:
>
> That’s a very interesting idea. It would probably need to be extended to 
> allow specifying that a type is like multiple types. Then the effective 
> “contract” would be the intersection of the operations provided by those 
> types. For example, we would want to be able to specify a type that is like 
> both string and []byte; it would support len, range, and indexing, but not + 
> or mutation.
>
> Combining this concept with the function syntax from the standard proposal, 
> here is what the classic Min function would look like:

Extending this a bit, you should be able to write:

type T like(int,float64)

as a type template, and then do things like:

type X template {
  F() T
}

Not sure if the idea will collapse when the details are worked out. I
can attempt if there is interest.


>
> func Min(type T like(int, float64))(a, b T) T {
>         if a < b {
>                 return a
>         }
>         return b
> }
>
> Andy
>
>

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