3 ms·
If you have a function that returns the first n elements of a vector, how do you make sure there are enough elements? Most languages would either insert a runti
by chongli 8y ago
If you have a function that returns the first n elements of a vector, how do you make sure there are enough elements? Most languages would either insert a runtime check or throw an exception at runtime. With a dependently typed language, you can do the check statically. This means knowing the provenance of n and the vector itself and doing a compile time proof that n can never exceed the length of the vector.
- blotter_paper 8y agoOkay, I see how that sort of check could be useful. I don't think it's impossible to do without dependant types in principle, but Rust isn't doing it AFAIK, and I see your point.