by goto11 · 3y ago · 0 comments
Type annotations are great for documentation and as a basic sanity test. They are especially useful with tools like code analysis or refactoring tools. But types are is no way a substitute for unit tests.
Sorry, I don't understand what you are saying here. By A and B are you referring to the correct output given an input, or just to the expected data type? Because there is a big difference, as with the `min()` example.
And the argument that if you can’t prove your design correct then there is no point proving your code correct is a strange one. That’s like saying that there is no point writing tests because you can’t prove your design correct or guarantee that all tests needed will be written. Ehhhh nope. I have written and generated more than 9000 tests for a very large scale C++ applications that are used by large corporations around the world. And I haven’t had a bug in production for 5+ years. However I of course can’t prove that those tests cover everything or that my design is correct. But that doesn’t mean it isn’t worth doing.
Since dependent type systems are just another kind of code, this is still true.
a * sin(x) + b * cos (-x)
should have been a * sin(x) - b * cos (x)
type isn't worth a damn here.In a lot of situations you have related values of exactly the same type: floats, strings, integers, Widget objects, which get mixed up.
A warning about variable shadowing or unused variable can be worth more than a type diagnostic. E.g. suppose
a * sin(x) - a * cos (x)
is written by mistake. If that causes b to be an unused local variable, we get a valuable diagnostic.