Remix.run Logo
addaon 4 days ago

> "making invalid states unrepresentable," a trick that is harder than it should be (though not impossible) in "less functional" languages

The flip side of this is to "make representable states valid." If you have an enum that doesn't fill a bitfield, values of the bitfield outside the enum are representable -- and the behavior of the system must be defined in that case. (Most often, this is done by mapping the behavior of undefined states to a chosen defined state, or using it to trigger an abort -- the key is that it must be an explicit choice.)