4 ms·
How is int*int*int*int*int or even int^5 better than a plain int[5]? To me, the use of mathematical operators * and ^ causes dissonance.
by jaipilot747 14y ago
How is
int*int*int*int*int
or even
int^5
better than a plain int[5]? To me, the use of mathematical operators * and ^ causes dissonance.
- munificent 14y agoIf you're coming from a type theory background (which, granted, few are), this operator is actually perfectly natural. http://en.wikipedia.org/wiki/Product_type http://en.wikipedia.org/wiki/Product_type
- lambdaphage 14y agoAren't product types just tuples, whereas arrays correspond to list types? The '^' operator can only construct arrays whose elements are of a single type, right?
- Yttrill 14y agoThat's correct. However, somewhat problematically, Felix considers the tuple int * int to actually be an array int ^ 2. It's not entirely clear this "automatically applied isomorphism" is a good idea though. However it means arrays "drop out" of the notion of a tuple as a special case. Internally such arrays have a special representation which allows arrays of 100,000 values, something which could never be represented by a tuple type (and still get reasonable compile times :)
- andrewflnr 14y agoI don't come from much of a type theory background. I certainly have no formal education in the field. I just know how a Cartesian product works, and that's enough to make me get it.