This is really going off on a tangent. Formally in a type algebra, (A, B) is a product type, so tupling is exponentiation. Outside of type theory, in pragmatic programming, + is frequently used for concatenation, which makes * or x defensible for tupling.
There's a principled type-theory argument that eliminates multiplication, but Swift already uses + for concatenation, which makes multiplication-like notation appropriate based on pragmatic considerations, unless you have a time machine to go back and fix +. So we cannot just appeal to first-principles here.
I would like whatever syntax we settle on to be clear and generalizable, ideally to both repeated values and multidimensional arrays (with repeated values being probably the more important consideration).
I don't love x as a symbol, because although it's fairly uncommon to use x as a name for an array count (though it does happen), it's very common to use it as a name for a repeated value in an array, which I would like this syntax to eventually generalize to (as Ben mentions): [5 x x] is ok, but it's reasonable to hope that we can do better.
It's probably worth talking a little bit about Fortran. Fortran is the gold standard for "array syntax sugar," 60 years later, with its flexible and concise (multidimensional) array syntax.
integer :: myArray(5) // array of five integers
real :: otherArray(3,4) // 3x4 array of floats
I don't think that we need to be quite this concise in Swift; for one thing, Swift is not oriented around concise array computation like Fortran is. For another thing, Fortran's doesn't generalize to values, which I think is a pretty desirable future direction¹.
So, some starting list of constraints that seem defensible from my perspective:
- It should be as minimally source-breaking as possible.
- Joe has argued, fairly convincingly, that the count should precede the type, mirroring the unsugared declaration. This rules out
Type[n] and variants (including directly-copying the Fortran syntax).
- It should visibly relate to existing array or tuple syntax (i.e. involve either
() or []). Unlike Tony, I don't think that a tuple association is something that we should to avoid, and it might help us get out of the box that we seem to be stuck in. InlineArray is extremely tuple-like (HomogeneousTuple was a working name for the concept for years).
¹ A Fortran programmer might use an implicit-DO construct instead, which is more powerful, but maybe a little bit too magical: [(n, i=1, 5)] // n five times