Structural type system
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. Structural systems are used to determine if types are equivalent and whether a type is a subtype of another. It contrasts with nominative systems, where comparisons are based on the names of the types or explicit declarations, and duck typing, in which only the part of the structure accessed at runtime is checked for compatibility.
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. Structural systems are used to determine if types are equivalent and whether a type is a subtype of another. It contrasts with nominative systems, where comparisons are based on the names of the types or explicit declarations, and duck typing, in which only the part of the structure accessed at runtime is checked for compatibility. # let x = object val mutable x = 5 method get_x = x method set_x y = x unit > = Here the OCaml interactive runtime prints out the inferred type of the object for convenience. Its type ( unit > ) is defined only by its methods. In other words, the type of x is defined by the method types "get_x : int" and "set_x : int -> unit" rather than by any name. To define another object, which has the same methods and types of methods: # let y = object method get_x = 2 method set_x y = Printf.printf "%d\n" y end;; val y : unit > = OCaml considers them the same type. For example, the equality operator is typed to only take two values of the same type: # x = y;; - : bool = false So they must be the same type, or else this wouldn't even type-check. This shows that equivalence of types is structural. One can define a function that invokes a method: # let set_to_10 a = a#set_x 10;; val set_to_10 : 'a; .. > -> 'a = The inferred type for the first argument ( 'a; .. > ) is interesting. The .. means that the first argument can be any object which has a "set_x" method, which takes an int as argument. So it can be used on object x : # set_to_10 x;; - : unit = () Another object can be made that happens to have that method and method type; the other methods are irrelevant: # let z = object method blahblah = 2.5 method set_x y = Printf.printf "%d\n" y end;; val z : unit > = The "set_to_10" function also works on it: # set_to_10 z;; 10 - : unit = () This shows that compatibility for things like method invocation is determined by structure. Let us define a type synonym for objects with only a "get_x" method and no other methods: # type simpler_obj = ;; type simpler_obj = The object x is not of this type; but structurally, x is of a subtype of this type, since x contains a superset of its methods. So x can be coerced to this type: # (x :> simpler_obj);; - : simpler_obj = # (x :> simpler_obj)#get_x;; - : int = 10 But not object z , because it is not a structural subtype: # (z :> simpler_obj);; This expression cannot be coerced to type simpler_obj = ; it has type unit > but is here used with type The first object type has no method get_x This shows that compatibility for widening coercions are structural.
References
No reference rows published for this article.
Cite this article
MLA
"Structural type system." encyclopegia.org, 2026, https://encyclopegia.org/wiki/structural-type-system. Accessed 24 November 2026.
Chicago
"Structural type system." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/structural-type-system.
APA
encyclopegia.org. (2026). Structural type system. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/structural-type-system
Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON