Hacker News new | ask | show | jobs
by sepeth 4057 days ago
FP languages have algebraic data types for this. Why do they call it virtual structs? How are they different than ADTs?
4 comments

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.

"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).

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.
This is part one: The good part of Rust's ADT/Enum system. Next I presume is the bad part of it - namely how it caused pain when implementing DOM in Servo.
Rust enums are ADTs.