Algebraic data type – Computing Reference – eLook.org


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).

< Previous Terms Terms Containing algebraic data type Next Terms >
ALF
Alfl
algebra
ALGEBRAIC
algebraic
algebraic data type
constructed type
constructor
discriminated union
FP2
Algebraic Interpretive Dialogue
Algebraic Logic Functional language
Algebraic Manipulation Package
Algebraic Specification Language
algebraic structure

Best casinos
Glory Casino is one of Bangladesh's most prominent and generous online casinos, with 3,000+ slots and live games from top providers. Beginner-friendly and mobile-ready, it offers big welcome bonuses, fast payouts, and fair winning odds.
Wintomic Casino offers a calm, well-structured gaming experience with a wide range of quality slots and live games from trusted providers. With secure SSL encryption, fair RNG play, and clear bonus terms, it's built for smooth, reliable fun.
Play the best casino games on Banger Casino across mobile and desktop and win real money! Enjoy a massive slots library, live dealers, and table games, plus a 125% welcome bonus up to €250 under a valid Curaçao license. Sign up today.
Divine Casino delivers a secure, stylish gaming experience with thousands of slots, live dealers, crash games, and sports betting. Claim a generous welcome bonus with free spins, enjoy fast withdrawals, and play with 24/7 support.

© Copyright 2026 elook.games
Powered by WordPress | Mercury Theme