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) In case you can't decipher it: var x : int ^ 3 * int ^ 2 = ((1,2,3), (4,5)); and the isomorphism would linearise it to an array of 5 ints indexed by either case 0 of 3 (i) where i:3 case 1 of 2 (j) where j:2 in other words "pick one of the top level tuple elements, then index that with modulo 3 or modulo 2 index (respectively). Another law of arithmetic is also intriguing and needs consideration: T + T + T <---> 3 * T Of course, the pair (caseno, value) is a fairly standard representation of sum types so it would be cool if Felix could represent that in a nice way. CAVEAT!!!! There's a gotcha! Consider that at the moment you can slice a tuple (1,2,"s") ---> slice off last element --> (1,2) as a kind of subtyping thing. This can be done without copying in the sense that the representation of (1,2) is just the "first bit" of (1,2,"s"). This will no longer work in general since compact linear types: (false, true, "s") --> struct { int mem0; int mem1; string s; } (false, true) --> int And this also means that some tuples do not have addressable components. Recall: type bool = 2; case 0 of bool <--> false case 1 of bool <--> true Now consider bool ^ 64 In some languages .. like C .. that's an array of 64 ints. In Felix now .. that's an array of 64 BITS compressed into a single integer. Yes, it really is. And it will screw up at the moment because int is only 32 bits on OSX, Windows, Linux and most other platforms! And there's no check! To be fixed!! -- john skaller skal...@users.sourceforge.net http://felix-lang.org ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language