4 ms·
I don't want to write a validator and litter calls to it throughout my code base. I want the "validator" to be the constructor of a type (or a refinement mecha
by ragnese 5y ago
I don't want to write a validator and litter calls to it throughout my code base.
I want the "validator" to be the constructor of a type (or a refinement mechanism, etc).
Then every function in my code base can have a clear contract via its type signature. What good is a function that says it accepts a string and returns a string if it actually just explodes when given some strings? That's not the same thing as returning a string...
I want to do three-ish things:
1. Make my function's type signature be correct. It is NOT correct to say that you accept an "int" but actually crash if you're given `0`.
2. Push bug catching to compile time instead of runtime. Calling a validation function inside a function is a runtime check. In the meantime I can write 100 calls to a function that I know will cause a crash and the compiler will say nothing.
3. Push type requirements to the callers of functions. Everyone preaches "validate at the edges", but if your function signatures had very precise types, that would happen "automatically." Your code won't compile unless you pipe the correct types all the way from the top function call down to the bottom one.