| > Different names for the same thing. No, different names for completely different concepts. > This says that the function isn't polymorphic in its argument, not that the types aren't polymorphic. Function resolution that is not polymorphic is not limited to Go, but occurs in inheritance-based languages, too. Example in OCaml: Struct types in Go are not polymorphic in anyway period, the only way to achieve polymorphism in Go is through interfaces which are not concrete types, unlike classes. > [1] Like Go, OCaml uses structural subtyping. No it doesn't. There is no subtyping in Go. There is only type conversion and type assertion. Whatever you wrote with OCaml is completely irrelevant to the discussion as the type systems are fundamentally different. but let's pretend it is. It's interesting that you didn't bother try writing the equivalent of `let f (x: #a) = ()` in Go, because you CANNOT. An interface IS NOT a substitute for OCaml inheritance, as the later is more precise and specialized. So no, Go doesn't support inheritance at its core. That's a false assertion. Go interfaces do not give a damn about what the actual implementation is, unlike OCaml sub classes. |
There is. Go simply has structural subtyping [1] rather than nominal subtyping.
> It's interesting that you didn't bother try writing the equivalent of `let f (x: #a) = ()` in Go, because you CANNOT.
You forget that OCaml also uses structural subtyping. Writing `#a` is effectively the shorthand for the inferred interface. So you can write it also as:
where is the interface of any class implementing at least a method `foo` of type `int`, i.e. what you'd write as in Go. You just don't in practice, because `#a` is both more convenient and readable.And the corresponding Go function would be:
[1] https://en.wikipedia.org/wiki/Structural_type_system