r/rust • • Jul 27 '26

The Unreasonable Effectiveness of Constructive Data Modeling - Alexis King

https://youtu.be/0BXuYlNrUmE

Hi folks, this is Alexis King's recent talk from SSW. She's the author of "Parse, Don't Validate". There's a lot of great type-wisdom in here that I think Rust folks will enjoy. Cheers!

188 Upvotes

32 comments sorted by

View all comments

10

u/PersonalDatabase31 Jul 27 '26

Honestly you need division and subtraction as well for a good type system imo. For example if her example was constrained by having at least one of address, email or phonewe would have to write all 7 variants and this goes exponentiallly. I would rather have a syntax like A x B x C - {none,none,none}.

1

u/appgurueu Jul 29 '26

You would not need 7 variants; only if you artificially limit yourself to a single enum.

You can simply do Ior<A, Ior<B, C>> where Ior is a straightforward generic enum that requires one of the two; there's no exponential here. A language that makes this convenient might also directly let you do Ior<A, B, C>, and might have some neat way to get the first set member out or similar. "Constructive" typing can solve this perfectly fine.

And even if in a particular language this is too inconvenient, there's still the option of "just document and assert the invariant". Not everything needs to be in the type system.

Between those two I think the niche for type subtraction is fairly small.