How to show that the Rust type system supports algebraic data types (ADTs)?

Viewed 2386

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 of A or the values of B.
  • Multiplication - Tuple (A, B) in Rust - operation that can return all the combinations of A and B.

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?

1 Answers
Related