Beyond Memory Safety with Types
insanitybit.github.io
insanitybit.github.io
One problem is where to put your state-specific type info when you're not using it. When you're a thread and your state information is tied to where control is, this is fine. When you're an object which gets called with events, where do you keep this type-specific info? Something like a variant record with all the possible states?
I think it's especially the linear types (or "affine", which is the Rust's variety of almost-linear types) that allows for this kind of statically-checked state machines.
Using Unique Ptr it's a bit hard IIRC (it's been 2 years since I've written C++) but still possible.
True, but languages with support for affine types are, to my knowledge, uncommon.
"One problem is where to put your state-specific type info when you're not using it."
Can you elaborate? I have not run into this issue.