| Tagged Union |
Article Index for Tagged |
Website Links For Union |
Information AboutTagged Union |
| CATEGORIES ABOUT TAGGED UNION | |
| data structures | |
| articles with example pascal code | |
| articles with example algol 68 code | |
| articles with example c code | |
|
Tagged unions are most important in functional languages such as ML and Haskell , where they are called datatypes (see Algebraic Data Type ) 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 comes with two introduction forms and . The elimination form is case analysis: if has type and and have type under the assumptions and respectively, then the term |
|
|