4 ms·
This reminds me a lot of Parse, don't Validate (by the same author, apparently): https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/ https://lex
by piinbinary 6y ago
This reminds me a lot of Parse, don't Validate (by the same author, apparently): https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/ https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-va...
I think there's another reason to make invalid states inexpressible in the type. When you need to change existing code (perhaps years after it was first written) in a way that breaks key assumptions, you find that the current types don't allow expressing that change. This is a good warning sign that other code will need to be updated to take the new states into account. Without the type enforcing that invariant, it might have been much harder to tell that this particular change (out of all the changes you make over the years) is the one that breaks a key assumption. (A key assumption that might have been forgotten by now!)
Types become a message to your future self.