Nominative type system

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

This box: view · talk · edit

In computer science, a nominal or nominative type system (or name-based type system) is a major class of type system, in which compatibility and equivalence of data types is determined by explicit declarations and/or the name of the types. Nominative systems are used to determine if types are equivalent, as well as if a type is a subtype of another. It contrasts with structural systems, where comparisons are based on the structure of the types in question and do not require explicit declarations.

Contents

Nominal typing

Nominal typing means that two variables are type-compatible if and only if their declarations name the same type. For example, in C, two struct types with different names are never considered compatible, even if they have identical field declarations.

However, C also allows a typedef declaration, which introduces an alias for an existing type. These are merely syntactical and do not differentiate the type from its alias for the purpose of type checking. This feature, present in many languages, can result in a loss of type safety when (for example) the same primitive integer type is used in two semantically distinct ways. Haskell provides the C-style syntactic alias, as well as a declaration that does introduce a new, distinct type, isomorphic to an existing type.

Nominal subtyping

In a similar fashion, nominal subtyping means that one type is a subtype of another if and only if it is explicitly declared to be so in its definition. Nominally-typed languages typically enforce the requirement that declared subtypes be structurally compatible (though Eiffel allows non-compatible subtypes to be declared). However, subtypes which are structurally compatible "by accident", but not declared as subtypes, are not considered to be subtypes.

C, C++, C# and Java all primarily use both nominal typing and nominal subtyping.

Some nominally-subtyped languages, such as Java and C#, allow classes to be declared final (or sealed in C# terminology), indicating that no further subtyping is permitted.

Comparison

Nominal typing is useful at preventing accidental type equivalence, and is considered to have better type-safety than structural typing. The cost is a reduced flexibility, as, for example, nominal typing does not allow new super-types to be created without modification of the existing subtypes.

See also

Notes

External links


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

  • 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 …   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

  • Nominative–accusative language — Nominative accusative alignment Linguistic typology Morphological Isolating Synthetic …   Wikipedia

  • Abstract type — This article discusses types with no direct members; see also Abstract data type. In software engineering, an abstract type is a type in a nominative type system which is declared by the programmer, and which has the property that it contains no… …   Wikipedia

  • Dutch declension system — Dutch declension is the declensional system of the Dutch language. Dutch marks nouns, pronouns, articles, and adjectives to distinguish case, number, and gender. Dutch can distinguish between four cases mdash;nominative, genitive, dative, and… …   Wikipedia

  • Тип данных — (встречается также термин вид данных)  фундаментальное понятие теории программирования. Тип данных определяет множество значений, набор операций, которые можно применять к таким значениям и, возможно, способ реализации хранения значений и… …   Википедия

  • Типизация данных — Тип данных  фундаментальное понятие теории программирования. Тип данных определяет множество значений, набор операций, которые можно применять к таким значениям, и, возможно, способ реализации хранения значений и выполнения операций. Любые… …   Википедия

  • Java — Иное название этого понятия  «Ява»; см. также другие значения. Не следует путать с JavaScript. Java Класс языка …   Википедия

  • Валютный тип — Тип данных Содержание 1 История 2 Определение 3 Необходимость использования типов данных …   Википедия

Share the article and excerpts

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