Record (computer science)

From Wikipedia, the free encyclopedia

This article is about the data structure and the type.

In computer science, a record type is a type whose values are records, i.e. aggregates of several items of possibly different types. The items being aggregated are called fields (or members) and are usually identified or indexed by field labels, names identifying the fields.

Record types are mathematically equivalent to product types but they usually behave differently with respect to typing: in most if not all typed programming languages, record types are bound to names and two record types are equal for the type system if and only if they have the name. This contrasts with product types where the equality is the equality of each of the type components individually.

[edit] Record types in programming languages

COBOL was the first programming language to support records directly. Algol got it from COBOL, and Pascal got it, more or less indirectly, from Algol; both of them had a notion of record type. C uses the terms struct or structure for both a record and its type. Records and record types are also present in functional programming languages.

Objects, in object-oriented languages, are an example of record and record types correspond to pure virtual classes (even if in practice, partially instantiated classes are used with the same functionality as record types provide). Note that in object-oriented design, record types relate to object composition.

The notion of signature in modular functional programming is another form of record type. If one leaves away the question of subtyping, a module implementation corresponds to a record of type a signature.

[edit] Representation in memory

The representation of records in memory varies depending on the programming languages, ranging from the juxtaposition of the components in a consecutive block of memory to an array of pointers pointing to the components.

The evolution of the implementation of records reveals the evolution of the concept, starting from the initial use as a collection of data of fixed complexity to the more general notion of a collection of data of any arbitrary complexity, including functions.

[edit] See also