3 ms·
> It has Structural Typing! Amazing! I wouldn't say Go has structural typing. It has a form of interfaces, which are not the same. Structural typing is when t
by wyager 10y ago
> It has Structural Typing! Amazing!
I wouldn't say Go has structural typing. It has a form of interfaces, which are not the same.
Structural typing is when the data members of an object are expressed in its type. For example, `x : {f : t}` is a statement that the object `x` has a member called `f` of type `t`. That is structural typing.
On the other hand, what Go has is pretty much the definition of interfaces, where you have constraint types that indicate that anything satisfying the constraint has some functions defined on it.
- tiglionabbit 10y agoAh, ok. I'll change my comment. I've heard it referred to as structural typing though, and googling "structural typing vs duck typing" gets the right results.
- leshow 10y agoThis isn't the same concept as structural typing I don't think, but purescript has something called extensible records that quite similar to what the previous poster describes: function :: forall a. { f :: String, g :: String | a } -> String This is a function that takes an extensible record. i.e. 'a' is some type which has fields f of type String and g of type String, at minimum.
- wyager 10y agoExtensible records are a form of structural typing. Purescript has good support for both nominal (via data declarations) and structural (via extensible records) typing. It has the best native support for both paradigms of any language that I can think of off the top of my head.
- mseepgood 10y agofunc example(x interface{f() string; g() string}) string { } Go's structural typing is based on methods instead of fields, but it's structural typing as well.