3 ms·
A proper sum type would go way beyond that because each state would only contain (and have access to) the relevant data as well, whereas with a C-style enum the
by masklinn 7y ago
A proper sum type would go way beyond that because each state would only contain (and have access to) the relevant data as well, whereas with a C-style enum the data is "sibling" to the enum, and so you generally get possibly garbage or irrelevant data in every state and the possibility for that garbage to not be properly initialised or overridden on state transition.
And the compiler would further ensures that you are handling every possible state at every level.
One problem I've often encountered with UI state machines is the explosion in error states, and the "proper" handling of invalid state transitons (unexpected operations) not from a technical perspective but from a UI perspective.