Programming/Language/Concept/Type/Structural
Properties
- tags
- Term
- alias
- Structural Typing
Structural typing
- Structural typing accepts a value wherever a vehicle-shaped type is expected if it has the required methods or fields, whether or not anyone wrote “implements Vehicle.”
- Shorthand: you count as a
Vehiclebecause you match the shape. The checker cares about members and their types. - Opposite pole: nominal typing.
Languages
Scala
- Inline structural type when you want matching members without a shared nominal
trait Vehicle: def driveAway(v: { def wheelCount: Int; def honk(): String }) = v.honk()- Scala 2 often uses reflection for this; many teams avoid it in hot code. Scala 3 keeps structural types; idiomatic code still favors nominal
trait Vehicleunless there is a concrete reason not to.
- Inline structural type when you want matching members without a shared nominal
Duck typing
Scala refinements
JS prototypes
Nominal vs structural
Terminology