Re:Go-internals: Chapter 2, “Interfaces” released
by ivoras on Monday April 09, 2018 @04:29PM
(#16796700)
It surprised me how go's interfaces have non-trivial limitations. What lately bit me is illustrated in the following snippet: the call to doSomething() is just not possible in Go:
I understand why the current implementation of Go doesn't work that way, and that the meta-reason for this not being implemented is the "we don't want generics" attitude, since it would effectively require 2 different compilations of doSomething(), one which accepts a slice of interfaces, which are a (pointer,type) tuple, and one which accepts an slice of this specific struct which happens to actually implement the I interface, and that's a taboo, but come on... it just weakens the idea of interfaces. It could have been done as a compile-time work-around which constructs the slice-of-interfaces argument on-the-fly before calling the function - it wouldn't have been the only magical thing in Go.
[ Parent
| on HN ]
Re:Go-internals: Chapter 2, “Interfaces” released
by leaveyou on Monday April 09, 2018 @04:57PM
(#16796934)
>It could have been done as a compile-time work-around which constructs the slice-of-interfaces argument on-the-fly before calling the function - it wouldn't have been the only magical thing in Go.
Is there a language that works the way you describe ?