| dbpprop:abstract
|
- In computer science, a tagged union, also called a variant, variant record, discriminated union, or disjoint union, is a data structure used to hold a value that could take on several different, but fixed types. Only one of the types can be in use at any one time, and a tag field explicitly indicates which one is in use. It can be thought of as a type which has several "cases," each of which should be handled correctly when that type is manipulated. Like ordinary unions, tagged unions can save storage by overlapping storage areas for each type, since only one is in use at a time. Tagged unions are most important in functional languages such as ML and Haskell, where they are called datatypes and the compiler is able to verify that all cases of a tagged union are always handled, avoiding many types of errors. They can, however, be constructed in nearly any language, and are much safer than untagged unions, often simply called unions, which are similar but do not explicitly keep track of which member of the union is currently in use. Tagged unions are often accompanied by the concept of a constructor, which is similar but not the same as a constructor for a class. Constructors produce a tagged union value, given the initial tag value and a value of the corresponding type. Mathematically, tagged unions correspond to disjoint or discriminated unions, usually written using +. Given an element of a disjoint union A + B, it is possible to determine whether it came from A or B. If an element lies in both, there will be two effectively distinct copies of the value in A + B, one from A and one from B. In type theory, a tagged union is called a sum type. Notations vary, but usually the sum type <math>A+B</math> comes with two introduction forms <math>\mathrminj_1 : A \to A+B</math> and <math>\mathrminj_2 : B \to A+B</math>. The elimination form is case analysis, known as pattern matching in ML-style programming languages: if <math>e</math> has type <math>A+B</math> and <math>e_1</math> and <math>e_2</math> have type <math>\tau</math> under the assumptions <math>x:A</math> and <math>y:B</math> respectively, then the term <math>\textttcase\ e\ \textttof\ x \Rightarrow e_1 | y \Rightarrow e_2</math> has type <math>\tau</math>. The sum type corresponds to intuitionistic logical disjunction under the Curry-Howard correspondence. An enumerated type can be seen as a degenerate case: a tagged union of unit types. It corresponds to a set of nullary constructors and may be implemented as a simple tag variable, since it holds no additional data besides the value of the tag.
- Rekord z wariantami jest to rodzaj rekordu, posiadającego tę właściwość, że zbiór rekordów posiada wspólny typ lecz różną postać, określoną aktualną wartością specjalnego pola znacznikowego.
- 标签联合(tagged union)也称可辨识联合(discriminated union)或者变体类型(variant type),指的是这样的一种数据结构,它能够存储一组不同但是固定的类型中某个类型的对象,具体是哪个类型由标签字段决定。这种数据结构在解释器、数据库和数据通信中非常有用。需要注意的是,可辨识联合英文原词在数学中又指不相交并集(disjoint union)。
|
| rdfs:comment
|
- In computer science, a tagged union, also called a variant, variant record, discriminated union, or disjoint union, is a data structure used to hold a value that could take on several different, but fixed types. Only one of the types can be in use at any one time, and a tag field explicitly indicates which one is in use. It can be thought of as a type which has several "cases," each of which should be handled correctly when that type is manipulated.
- Rekord z wariantami jest to rodzaj rekordu, posiadającego tę właściwość, że zbiór rekordów posiada wspólny typ lecz różną postać, określoną aktualną wartością specjalnego pola znacznikowego.
- 标签联合(tagged union)也称可辨识联合(discriminated union)或者变体类型(variant type),指的是这样的一种数据结构,它能够存储一组不同但是固定的类型中某个类型的对象,具体是哪个类型由标签字段决定。这种数据结构在解释器、数据库和数据通信中非常有用。需要注意的是,可辨识联合英文原词在数学中又指不相交并集(disjoint union)。
|