I couldn’t find any prior discussion on this subject, so I hope you don’t mind that I start it.
My main interest in Rust is for scientific computing, and specifically numerical mathematics, which means I work with matrices a lot. Currently, the available linear algebra crates (I’m mostly familiar with rulinalg and ndarray) index matrices (2d arrays) like this:
x[[i, j]]
// Or
x[(i, j)]
It’s not a very big deal, but the redundant brackets don’t exactly help readability when you’re dealing with algorithms that do complex patterns of indexing. Of course, it would be neat if one could instead do this:
x[i, j]
One very obvious way to accomplish this is to provide syntax sugaring when the index type is a tuple. That is,
x[i, j] becomes x[(i, j)]
The reason I want a tuple is that I want to be able to mix the types, so one could do things like
x[i, ..]
for retrieving the row of index i in the matrix.
Syntax sugaring tuples is only one way to accomplish this, but it seems the most straightforward from my own naive point of view, having little to no knowledge of Rust internals. My goal with this post is to get a feeling for what kind of opinions people have for this matter. In addition:
- Are there any technical reasons that would prohibit this kind of syntax sugaring?
- Are there any language-philosophical reasons that would prohibit this syntax sugar?
- Are there any other concerns with this?
I’d be very interested to hear some view points. Thanks!