3 ms·
Yes they are. And actually they would play nice with generics! Imagine type Ord a interface { Compare(a) int } Also it would be nice to do somet
by whateveracct 10y ago
Yes they are. And actually they would play nice with generics! Imagine
type Ord a interface {
Compare(a) int
}
Also it would be nice to do something like
func Max[a <: Ord a](a, a) a
(Syntax stolen from Scala)
Right now, interfaces are too opaque. You can't take a value of interface type X and return the same type. You have to return an opaque X, which gives you no guarantees about its concrete implementation. Parametricity is an extremely well-motivated and solved language feature!
I think if you add parametricity to Go functions (not even parametric types. Just type variables that play nice with all the builtins) you can write this and get guarantees about its implementation (assuming it follows the functor laws)
func map[a,b](func(a) b, []a) []b