This breaks down because it's not easy to statically reason about when a variable is a NonZeroNumber. For example, what is the type signature for subtraction of two NonZeroNumbers? You can't guarantee that it isn't zero, so it has to be a Number. Thus, you can't divide by the difference. You could use a more powerful type system to reason about these kinds of constraints, but then type checking quickly becomes undecidable (or at least very, very expensive).
naasking|2 years ago
You can encode this failure as well, so at least the possibility becomes explicit:
Oleg also showed you can make an even safer statically checked version with pretty standard type theory and modules:https://okmij.org/ftp/Computation/lightweight-guarantees/lig...
vidarh|2 years ago
tromp|2 years ago