5 ms·
The typestate concept seems like an incredibly cool tool for enforcing static guarantees. As far as I'm aware, not even Haskell has anything similar to that (fe
by thurn 15y ago
The typestate concept seems like an incredibly cool tool for enforcing static guarantees. As far as I'm aware, not even Haskell has anything similar to that (feel free to correct me!)
- thyrsus 15y agoI'm not clear: is typestate a compile time or run time guarantee? [Edit] That is, is the guarantee implemented at compile time, noting violations similarly to syntax violations, or does it generate "invisible" code that performs runtime checks which can throw something similar to exceptions?
- cwp 15y agoA bit of both, actually. It's mostly compile-time checking, but you can also write assertions about the typestate of a particular variable. The compiler generates code to check the actual values at runtime - if the assertion fails, the program is aborted. The really cool bit is that the compiler can take the assertions into account when compiling code that follows the assertions.
- divtxt 15y agoIt's like design by contract (preconditions/postconditions) without classes. Interesting parallel to how Go has interfaces without classes.