Algebraic data types are named so because they form "initial algebra",
+ represents sum types (disjoint unions, eg Either). • represents product types (eg structs or tuples) X for the singleton type (eg data X a = X a) 1 for the unit type () and μ for the least fixed point (eg recursive types), usually implicit.
from these operators can be built all the usual data types. Algebraic data types also support parametric polymophism, which means that they can be used as constants for any basic type with static security guarantees. In addition, ADTs have a single syntax for introducing and eliminating data types (through constructors and pattern matching). For instance.
The richness and uniformity of the types of algebraic data, as well as the fact that they are immutable, distinguishes them from OO objects, which are largely:
- represent only product types (therefore no recursive or summarized types)
- do not support pattern matching
- are mutable
- do not support parametric polymorphism
source share