Structural type system

Structural type system

A structural type system is a major class of type system, in which type compatibility and equivalence are determined by the type's structure, and not through explicit declarations. Structural systems are used to determine if types are equivalent, as well as if a type is a subtype of another. It contrasts with nominative systems, where comparisons are based on explicit declarations or the names of the types, and duck typing, in which only the part of the structure accessed at runtime is checked for compatibility..

In structural typing, two objects or terms are considered to have compatible types if the types have identical "structure". Depending on the semantics of the language, this generally means that for each feature within a type, there must be a corresponding and identical feature in the other type. Some languages may differ on the details (such as whether the "features" must match in name).

Haskell, ML, [http://ssdl-wiki.cs.technion.ac.il/wiki/index.php/Whiteoak Whiteoak] and Objective Caml are examples of structurally-typed languages. [http://haxe.org HaXe] uses structural typing, although classes are not structurally subtyped.

In languages which support subtype polymorphism, a similar dichotomy can be formed based on how the subtype relationship is defined. One type is a subtype of another if and only if it contains all the "features" of the base type (or subtypes thereof); the subtype may contain additional features (such as members not present in the base type, or stronger invariants).

Structural subtyping is arguably more flexible than nominative subtyping, as it permits the creation of "ad hoc" types and interfaces; in particular, it permits creation of a type which is a supertype of an existing type T, without modifying the definition of T. However this may not be desirable where the programmer wishes to create closed abstractions.

A pitfall of structural typing versus nominative typing is that two separately defined types intended for different purposes, each consisting of a pair of numbers, could be considered the same type by the type system, simply because they happen to have identical structure. One way this can be avoided is by creating one algebraic data type for one use of the pair and another algebraic data type for the other use.

External links

* [http://www.cis.upenn.edu/~bcpierce/tapl/main.html "Types and Programming Languages" by Benjamin Pierce (MIT Press 2002)]
* [http://www.c2.com/cgi/wiki?NominativeAndStructuralTyping c2.com: Nominative and structural typing]


Wikimedia Foundation. 2010.

Игры ⚽ Нужна курсовая?

Look at other dictionaries:

  • Type system — Type systems Type safety Inferred vs. Manifest Dynamic vs. Static Strong vs. Weak Nominal vs. Structural Dependent typing Duck typing Latent typing Linear typing Uniqueness typing …   Wikipedia

  • Nominative type system — Type systems Type safety Inferred vs. Manifest Dynamic vs. Static Strong vs. Weak Nominal vs. Structural Dependent typing Duck typing Latent typing Linear typing Uniqueness typing …   Wikipedia

  • Nominative and structural type systems — are: Nominative type system Structural type system The differences between nominative and structural type systems are discussed in: Type system Subtype This disambiguation page lists articles associated with the same title. If an …   Wikipedia

  • Structural anthropology — is based on Claude Levi Strauss s idea that people think about the world in terms of binary opposites such as high and low, inside and outside, person and animal, life and death and that every culture can be understood in terms of these opposites …   Wikipedia

  • Structural engineering — is a field of engineering dealing with the analysis and design of structures that support or resist loads. Structural engineering is usually considered a speciality within civil engineering, but it can also be studied in its own right. [cite… …   Wikipedia

  • Structural equation modeling — (SEM) is a statistical technique for testing and estimating causal relations using a combination of statistical data and qualitative causal assumptions. This definition of SEM was articulated by the geneticist Sewall Wright (1921),[1] the… …   Wikipedia

  • Type II topoisomerase — Type II topoisomerases cut both strands of the DNA helix simultaneously in order to change the linking number of the molecule. FunctionOnce cut, the ends of the DNA are separated, and a second DNA duplex is passed through the break. Following… …   Wikipedia

  • Structural dynamics — is a subset of structural analysis which covers the behaviour of structures subjected to dynamic loading. Dynamic loads include people, wind, waves, traffic, earthquakes, and blasts. Any structure can be subject to dynamic loading. Dynamic… …   Wikipedia

  • Structural Integration — is a type of Alternative medicine which aims to align the human body in the gravitational field. [ [http://www.theiasi.org/whatis.php What is Structural Integration? ] ] The claimed benefit is that the increased use of balance at finer levels of… …   Wikipedia

  • Structural adjustment — is a term used to describe the policy changes implemented by the International Monetary Fund (IMF) and the World Bank (the Bretton Woods Institutions) in developing countries. These policy changes are conditions (Conditionalities) for getting new …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”