4 ms·
They're not very different in that arrays can be thought of as a more specialized form of tuples that can thus coerce to slices. In theory, arrays do not need
by Blikkentrekker 6y ago
They're not very different in that arrays can be thought of as a more specialized form of tuples that can thus coerce to slices.
In theory, arrays do not need to exist, and could in theory be expressed as tuples, but that would lead to rather unpleasant syntax. `(A, A, A, A, A, A, A, A, A, A)` is certainly not as nice as `[A; 10]`; — Rust could even have chosen to make the latter syntactic sugar for the former and make them interchangeable.
The crux to this, is that in Rust, unlike in many other languages, the length of an array is static and known at compile time. Many languages lack such a datatype, as it isn't strictly needed per the aforementioned reasons.
- steveklabnik 6y ago... and in some sense, tuples are also isomorphic to structs. Product types: woo!
- andrewflnr 6y agoThere's at least one language (Haxe?) that uses exponentiation syntax for array types, playing in the product type idea: (A,A,A,A) = A^4