I didn't really understand your original post. I don't understand how
it helps address the issues people face with generics. I don't know
what "make(interface{})" means.
that should have been; "make(chan interface{})"
For example, one of the major reasons people want generics is so that
they can write a compile-time type-safe container that is not a slice
or a map. Can you give an example of how to write such a thing?
i was only looking at read over iteration, so only range needed to be overloaded for interfaces, for general generic containers the slice access builtin operator would also need to be overloaded for interfaces.
so;
a:=[]int{1,2,3,4,5}
var b interface{}
var c interface{}
b=a
c=1
b[3]=c // this would replace 3 with 1 into the third element of a.
but currently you can't refer to an element of an array without LOCALLY the type of the contents, but you can currently, using interfaces, write code that actually doesn't need to know. With interface overloads, and by passing into the scope functions that operate on interfaces, you could do anything you like to an unknown, in that scope, slice.
something like this, for a set;
func (this *Set) Insert(item interface{}, equals func(interface{},interface{})bool) {
if !this.Includes(item,equals){ // 'Includes' somehow checks if already in set, also using interfaces
this=append(this,item)
}
}
s:=Set{make(int,100)} // or something
compareInts:=func(a int,b int){return a==b}
s.Insert(1,compareInts) // compareInts could 'disappear' into a closure
size:=len(s) // since this is outside the 'generic' function this is just the non-overloaded use of len
so actually append() and len() would also need this overload.
if the compiler actually produces code doing the boxing/unboxing thats in your code, doesn't matter, it could general replace it with multiple static versions as required, or not.