9 Jul 2012 03:13

## Generalise array index coercion to arbitrary rank.

```So now, Felix implements coercions:

T ^ x0 ^ x1 ^ x2 ^.... ^ x(n-1) <---> T ^ ( x0 * x1 * x2 * ... * x(n-1))

(and pointers to the above)

that is, you can convert between an array of array of array of ... array of T
with indexes of constant unitsum type (modular integers), to or from
an array of T with indexes which are tuples, i.e. rank n matrices.

This is not fully general in that it doesn't support arbitrary conversions
of compact linear types (modulo n types and their sums and products).
That generalisation is actually easier to implement, and would allow,
for example, flattening an array of any structure. however this would
mean that you could coerce according to the isomorphism

a ^ 2 ^ 3 <--> a ^ 3 ^ 2

i.e. you could mess up the index order and convert between
2 x 3 matrices and 3 x 2 matrices (since they both use 6 elements).

Such a blunt reshaping can be useful (you can always do it with
a C_hack::cast!) but it doesn't "feel" like its "structure preserving".
The coercions above preserve structure in a stronger sense.

The general indexing scheme is extremely powerful!\
I have not implemented coercions involving sums (other than
unit sums):

T ^ x0 * T ^ x1 <---> T ^ (x0 + x1)
```