2 ms·
This is possible to do without dependent types. You could have something like this (using TS syntax): function produceComplexArray(arr: array<number>): Compl
by Zababa 6y ago
This is possible to do without dependent types. You could have something like this (using TS syntax):
function produceComplexArray(arr: array<number>): ComplexArray | null {
...
}
function consumeComplexArray(arr: ComplexArray) {
...
}
If the only place where you can produce a ComplexArray is produceComplexArray, and produceComplexArray ensures that the arrays it receives are "a monotonically increasing array of numbers with a mean value of such and such and a standard deviation of such and such", then all the functions after produceComplexArray can be assured that they have the right array. Therefore, even with a relatively simple type system, you can ensure this invariant.
I think I got this idea from this article: 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...