Wikipedia's list of programming languages with algebraic data types (ADTs) suggests that Rust indeed has ADTs, but I am not sure if my interpretation for why this is true for Rust is correct. As I understand it, to say that one has ADTs one needs to have:
Values:
- Zero (or Void) -
!in Rust) - a type that gets no value. - One (or Unit) -
()in Rust) - a type that gets one value:()itself.
Operations:
- Addition -
enum { A, B }in Rust - operation that can return the values ofAor the values ofB. - Multiplication - Tuple
(A, B)in Rust - operation that can return all the combinations ofAandB.
Rules:
a + b = b + a:enum { A, B } =~ enum { B, A }a * b = b * a:(A, B) =~ (B, A)0 + x = x:enum { !, A } =~ enum { A }0 * x = 0:(!, A) =~ !1 * x = x:((), A) =~ A
Here A =~ B means that there is a fn(A) -> B and fn(B) -> A
Is my description above for why Rust's type system supports ADTs true, or am I missing or misunderstanding something about it?