|
|
|
|
|
by rbehrends
3219 days ago
|
|
> There is no subtyping in Go. 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: let f (x: < foo: int; .. > ) = ()
where < foo: int; .. >
is the interface of any class implementing at least a method `foo` of type `int`, i.e. what you'd write as interface {
foo() int
}
in Go. You just don't in practice, because `#a` is both more convenient and readable.And the corresponding Go function would be: func f(x interface { foo() int }) {
}
[1] https://en.wikipedia.org/wiki/Structural_type_system |
|
No there is not, period.
is not sub typing. but it's interesting how you move the goal post on each comment. You go from inheritance to sub typing to "structural subtyping". You're not interested in a serious discussion.