Re:Virtual Structs Part 1: Where Rust’s Enum Shines
by sepeth on Tuesday May 05, 2015 @12:46PM
(#9493469)
FP languages have algebraic data types for this. Why do they call it virtual structs? How are they different than ADTs?
[ Parent
| on HN ]
Re:Virtual Structs Part 1: Where Rust’s Enum Shines
by jarrettc on Tuesday May 05, 2015 @12:55PM
(#9493525)
Rust has algebraic data types. They're one of Rust's most important features.
But algebraic data types do not in themselves provide a way to express the notion of a type with variants or sub-types.
Re:Virtual Structs Part 1: Where Rust’s Enum Shines
by eddyb on Tuesday May 05, 2015 @01:15PM
(#9493643)
"Virtual Structs" is a name for a potential feature that may expose some sort of structural inheritance or subtyping.
The name is not used for the current "enum" feature, which is one of the few ADTs in Rust (there's also "struct" and tuples - not sure what else qualifies).
Re:Virtual Structs Part 1: Where Rust’s Enum Shines
by pdpi on Tuesday May 05, 2015 @01:45PM
(#9493839)
enum gives you sum types, struct/tuples provide product types. That's pretty vanilla ADTs sorted. GADTs are a whole other can of worms though.