3 ms·
Type systems do not thinking for you, you still have to make a type with a range check. So you could just as well write function foo(n) { if(n < 10 || n
by z3t4 6y ago
Type systems do not thinking for you, you still have to make a type with a range check. So you could just as well write
function foo(n) {
if(n < 10 || n > 100) throw new Error("Expected n=" + n + " to be between 10 and 100");
return n*2;
}
And while you are at it you can write an unit test that is tested at compile time or in the editor/IDE.
// assert(foo(10),20);
- amw-zero 6y agoTry reading the tutorial. F* uses refinement types, which means that logic is checked before the program is executed, at compile time.
- tuvistavie 6y agoRuntime safety and compile time safety are not the same thing. Compile time safety is not a silver bullet but it does protect against quite a few classes of errors.