3 ms·
> Whereas most programming languages use nominal subtyping, Go is unique among mainstream typed programming languages in using structural subtyping. I thought
by TheDong 6y ago
> Whereas most programming languages use nominal subtyping, Go is unique among mainstream typed programming languages in using structural subtyping.
I thought typescript also used structural subtyping? i.e. in typescript I can define:
interface Stringer {
String: () => string
}
function takesStringer(s: Stringer) {}
And now I can call takesStringer with any class that happens to have a String() method.
This seems to match structural subtyping in go.
Am I missing some reason that this isn't structural subtyping as referred to in the paper? Do they mean to say that typescript isn't a "mainstream typed programming language"?
- deleted 6y ago[deleted]
- ImprobableTruth 6y agoIt absolutely does. It doesn't have any nominal typing at all, so even classes are compared structurally. I assume they're not considering it because typescript compiles to javascript, so it doesn't have the problem Go faces of how to generate code for its generics. The wording is definitely weird though.