Algebraic data type


algebraic data type
programming
(or “sum of products type”) in functional programming, new types can be defined, each of which has one or more constructors. such a type is known as an algebraic data type. e.g. in haskell we can define a new type, “tree”:
data tree = empty | leaf int | node tree tree
with constructors “empty”, “leaf” and “node”. the constructors can be used much like functions in that they can be (partially) applied to arguments of the appropriate type. for example, the leaf constructor has the functional type int -> tree.
a constructor application cannot be reduced (evaluated) like a function application though since it is already in normal form. functions which operate on algebraic data types can be defined using pattern matching:
depth :: tree -> int depth empty = 0 depth (leaf n) = 1 depth (node l r) = 1 + max (depth l) (depth r)
the most common algebraic data type is the list which has constructors nil and cons, written in haskell using the special syntax “[]” for nil and infix “:” for cons.
special cases of algebraic types are product types (only one constructor) and enumeration types (many constructors with no arguments). algebraic types are one kind of constructed type (i.e. a type formed by combining other types).
an algebraic data type may also be an abstract data type (adt) if it is exported from a module without its constructors. objects of such a type can only be manipulated using functions defined in the same module as the type itself.
in set theory the equivalent of an algebraic data type is a discriminated union – a set whose elements consist of a tag (equivalent to a constructor) and an object of a type corresponding to the tag (equivalent to the constructor arguments).
(1994-11-23)

Read Also:

  • Algebraic equation

    an equation in the form of a polynomial having a finite number of terms and equated to zero, as 2 x 3 + 4 x 2 − x + 7 = 0. historical examples he felt as he had when puzzling over the unknown quant-ty in an algebraic equation. jerome, a poor man mary e. […]

  • Algebraic extension

    a field containing a given field such that every element in the first field is algebraic over the given field.

  • Algebraic expression

    a symbol or a combination of symbols used in algebra, containing one or more numbers, variables, and arithmetic operations: how to solve algebraic expressions. historical examples an equation admits of description in two ways:— it may be regarded purely as an algebraic expression, or as a geometrical locus. encyclopaedia britannica, 11th edition, volume 9, slice […]

  • Algebraic function

    a function that can be expressed as a root of an equation in which a polynomial, in the independent and dependent variables, is set equal to zero. noun (maths) any function which can be constructed in a finite number of steps from the elementary operations and the inverses of any function already constructed compare transcendental […]

  • Algebraic geometry

    the study of sets that are defined by algebraic equations.


Disclaimer: Algebraic data type definition / meaning should not be considered complete, up to date, and is not intended to be used in place of a visit, consultation, or advice of a legal, medical, or any other professional. All content on this website is for informational purposes only.