/ˈstrʌktʃərəl/

adj.

relating to or forming part of the structure of a building or other item. A structural type system (or property-based type system) is a major class of type systems in which type compatibility and equivalence are determined by the type’s actual structure or definition and not by other characteristics such as its name or place of declaration. An important attribute of every type system is whether they are structural or nominal, they can even be mixed within a single type system. So it’s important to know the difference. A type is something like a string, a boolean, an object, or a class. They have names and they have structures. Primitives like strings or booleans have a very simple structure and only go by one name. More complex types like object or classes have more complex structures. They each get their own name even if they sometimes have the same structure overall. A static type checker uses either the names or the structure of the types in order to compare them against other types. Checking against the name is nominal typing and checking against the structure is structural typing.

In a structural type system, two types are deemed the same if they are of the same structure. In other words, if they have the same public fields and methods of compatible type/signature. Similarly, a type T1 is deemed a subtype of a type T2 if and only if T1 has all public members (of compatible type/signature) that T2 has (but may have more). In the example from the previous section, we said Product is not a (nominal) subtype of Person. In a structural type system, however, Product would indeed be deemed a (structual) subtype of Person because it has all of Person’s public members of compatible type (only field name” in this case). The opposite is, in fact, not true: Person is not a subtype of Product because it lacks Product’s field price.

relating to or forming part of the structure of a building or other item.

A structural type system (or property-based type system) is a major class of type systems in which type compatibility and equivalence are determined by the type’s actual structure or definition and not by other characteristics such as its name or place of declaration.

An important attribute of every type system is whether they are structural or nominal, they can even be mixed within a single type system. So it’s important to know the difference.

A type is something like a string, a boolean, an object, or a class. They have names and they have structures. Primitives like strings or booleans have a very simple structure and only go by one name.

More complex types like object or classes have more complex structures. They each get their own name even if they sometimes have the same structure overall.

A static type checker uses either the names or the structure of the types in order to compare them against other types. Checking against the name is nominal typing and checking against the structure is structural typing.

In a structural type system, two types are deemed the same if they are of the same structure. In other words, if they have the same public fields and methods of compatible type/signature. Similarly, a type T1 is deemed a subtype of a type T2 if and only if T1 has all public members (of compatible type/signature) that T2 has (but may have more).

In the example from the previous section, we said Product is not a (nominal) subtype of Person. In a structural type system, however, Product would indeed be deemed a (structual) subtype of Person because it has all of Person’s public members of compatible type (only field name” in this case). The opposite is, in fact, not true: Person is not a subtype of Product because it lacks Product’s field price.