4 ms·
Maybe I'm spoiled by TypeScript but this is how I'd do it in a structural typing system: type ConstrainedByW = | { w: false, x: false } | { w: true
by Hackbraten 2y ago
Maybe I'm spoiled by TypeScript but this is how I'd do it in a structural typing system:
type ConstrainedByW =
| { w: false, x: false }
| { w: true, x: bool }
type ConstrainedByY =
| { x: bool, y: false, z: bool }
| { x: true, y: true, z: false }
type ProgramState = ConstrainedByW & ConstrainedByY
- jandrese 2y agoYes, but certainly you can see how even a toy example with just 4 booleans is already getting complicated?
- Hackbraten 2y agoIt's certainly complicated. But not WTF-level complicated. Complexity is both subjective and relative. Allowing invalid states in your model is going to complicate things, too. I wouldn't mind having this example in production. It will scale just fine with the number of booleans.