3 ms·
“algebraic data types” includes product types (aka structs, classes and tuples) as well as sum types (aka enums and probably other names)
by nicoburns 5y ago
“algebraic data types” includes product types (aka structs, classes and tuples) as well as sum types (aka enums and probably other names)
- ebingdom 5y agoRust's "enums" also include products. Each case can have multiple arguments. That's a sum of products. "Algebraic data type" is the proper term for what Rust calls "enums", since they encompass both sums and products. (It is also true that structs are products. But that isn't relevant.)
- kibwen 5y agoRust's syntax makes plenty of concessions to familiarity, as a way of making up for the much more important and irreducible unfamiliarity that it brings to the table (e.g. ownership). Originally Rust used the keyword `tag` here (for "tagged unions"), then vacillated between `enum` and `union` for years and years prior to 1.0.