3 ms·
I would allow array indexing if the compiler can prove the bounds have been properly checked before use.
by bestouff 2y ago
I would allow array indexing if the compiler can prove the bounds have been properly checked before use.
- SkiFire13 2y agoThis is not that simple at all. For starters, what is a bound check? There's no such concept at the type level that the compiler can check. You'll need to add one such concept that propagates through functions, increasing the complexity of function signatures. And this still won't solve the problem of when you as a programmer know that something is definitely inbound but you can't express the proof in the language. Ultimately this means using `panic` (but you don't want to), dummy default values (but this is just `null` all over again!), adding dependent types (which AFAIK nobody has managed to do in a low level language, and even if it was possible it would add a lot of complexity) or just give up and accept your program cannot be accepted.