To my limited knowledge Algebraic Data Types in Haskell can be of two forms namely, sums (e.g. data Bool = True | False
) or products (e.g. data Pair = P Int Double
). Below are some data types with nullary and unary value constructors.
data Z = Z
data S n = S n -- I think that this is a singleton type?
data S = S Int
Are these types considered as algebraic data types? If so what are they called?
Z
is just a differently named unit type. A 1
as an ADT. In other words, it is an empty product type. (Likewise, a type with no constructors at all may be considered an empty sum type.)
S n
is isomorphic to n
itself. In the framework of ADTs, it is considered equivalent, i.e. if n
is an algebraic type then so is S n
.
Note however that in Haskell, type definitions are often deliberately treated as opaque, by way of avoiding to export the value constructors. The type is then rather an abstract data type instead of an algebraic one.