|
KUMI v5.0.0
Gorgeous Garnet
|
An identity element, or neutral element, of a binary operation \( \ast \) on a set is an element \( e \) such that \( e \ast a = a \ast e = a \) for every element \( a \), as 0 is for the addition of the natural numbers and 1 for their multiplication.
The sum and the product of types have identity elements as well, the empty type 0 and the unit type 1, for which the laws hold up to isomorphism rather than equality, \( A + 0 \cong A \) and \( A \times 1 \cong A \).
The empty type 0 has no value. It is the identity element of the sum, \( A + 0 \cong A \), since a choice between a value of \( A \) and a value that cannot exist amounts to a value of \( A \), and it absorbs the product, \( A \times 0 \cong 0 \), since a pair whose second component cannot exist cannot exist either.
C++ has no complete object type without values. The type void has an empty set of values, but it is an incomplete type that no object has, and a function returning void returns normally. A class whose default constructor is deleted keeps its copy and move constructors, so that a value of it can still be produced, by std::bit_cast among others.
The attribute [[noreturn]] marks a function that never returns, the runtime counterpart of a function to the empty type, although the attribute lies outside the type of the function:
The empty type has no counterpart in KUMI, since the library provides no sum type and C++ provides no empty type.
The unit type 1 has exactly one value, often written \( () \). It is the identity element of the product, \( A \times 1 \cong A \), since the second component of a pair whose second type has a single value carries no information, and it is the product of no type, the empty tuple.
The unit type of KUMI is kumi::unit, with the constant kumi::none, and the library recognizes a unit type through the concept kumi::concepts::unit_type, which accepts a product type of size 0, kumi::tuple<> among them, and std::nullptr_t:
An empty class such as struct unit {}; has a single value as well, yet it models no product-type concept of the library, since neither std::tuple_size nor std::tuple_element is specialized for it: