Some of the things I've learned every day since Oct 10, 2016
93: Subtypes (Programming)
January 16, 2017Posted by on
Let be data types in the type system of a programming language. To say that is a subtype of , often written , means that objects of type can be used where objects of type are expected. That is, is a more specific version of in some sense. (Equivalently, is said to be a supertype of .)
Subtyping forms a reflexive and transitive relation on a given set of types.
An (non-technical) example would be , where is the type of penguins, is that of flightless birds, and is that of birds. A penguin is acceptable where a bird or even a flightless bird is expected, but conversely not any bird will do when a penguin is expected.