| ▲ | Jtsummers an hour ago | |
If I'm building up a type checker and an interpreter, I very well could (continuing that example) end up with different data structures using the same discriminant (but containing different data about the system). In Rust I'd have to do something like:
And I'd have to hope they were both complete and match (at least according to what I know now, that's why I'm asking). If I go back in to the Parser enum and add a `un_minus`, then I have to also go into the Typer enum (apologies for the bad naming, I'm at work and commenting between my way too many meetings) and manually add it. I have no compile time guarantee that both are complete and synchronized. In Ada, I modify the existing enum and both will fail to compile until I add in the variant for `un_minus`. One edit, multiple failures distributed across the code base as a result telling me all the places where I have to add in a new code branch or new variant.EDIT: Run on sentence broken up. | ||
| ▲ | bombela 28 minutes ago | parent [-] | |
You can use one generic enum with a trait holding the payload type. I posted an example as response to your first comment. | ||