Record Types
Types of records give rise to the concepts of width and depth subtyping. These express two different ways of obtaining a new type of record that allows the same operations as the original record type.
Recall that a record is a collection of (named) fields. Since a subtype is a type which allows all operations allowed on the original type, a record subtype should support the same operations on the fields as the original type supported.
One kind of way to achieve such support, called width subtyping, adds more fields to the record. More formally, every (named) field appearing in the width supertype will appear in the width subtype. Thus, any operation feasible on the supertype will be supported by the subtype.
The second method, called depth subtyping, replaces the various fields with their subtypes. That is, the fields of the subtype are subtypes of the fields of the supertype. Since any operation supported for a field in the supertype is supported for its subtype, any operation feasible on the record supertype is supported by the record subtype. Depth subtyping only makes sense for immutable records: for example, you can assign 1.5 to the 'x' field of a real point (a record with two real fields), but you can't do the same to the 'x' field of an integer point (which, however, is a deep subtype of the real point type) because 1.5 is not an integer.
Subtyping of records can be defined in System F<:, which combines parametric polymorphism with subtyping of record types and is a theoretical basis for many functional programming languages that support both features.
Some systems also support subtyping of labeled disjoint union types (such as algebraic data types). The rule for width subtyping is reversed: every tag appearing in the width subtype must appear in the width supertype.
Read more about this topic: Subtyping
Famous quotes containing the words record and/or types:
“... many of the things which we deplore, the prevalence of tuberculosis, the mounting record of crime in certain sections of the country, are not due just to lack of education and to physical differences, but are due in great part to the basic fact of segregation which we have set up in this country and which warps and twists the lives not only of our Negro population, but sometimes of foreign born or even of religious groups.”
—Eleanor Roosevelt (18841962)
“The bourgeoisie loves so-called positive types and novels with happy endings since they lull one into thinking that it is fine to simultaneously acquire capital and maintain ones innocence, to be a beast and still be happy.”
—Anton Pavlovich Chekhov (18601904)