[swift-evolution] [Pitch] New Version of Array Proposal

David Sweeris davesweeris at mac.com
Sun Jul 23 13:21:46 CDT 2017

> On Jul 23, 2017, at 09:08, Taylor Swift <kelvin13ma at gmail.com> wrote:
> let fsa:[2 * Int] = [2 * 5, 3] // [10, 3] ???

Correct. If you wanted a multidimensional array, that'd be written "let nestedFSA: [2*[5*Int]]". Or, speculating a bit, I suppose maybe "let nestedFSA: [[5*Int]*2]", if we wanted there to be a column-major option. IMHO all those read better than this proposal's syntax.

> Using the multiplication operator as a separator character seems like an extraordinarily bad idea.

Well, much to the dismay of my occasionally-inner Unicode fanboy, we decided that we didn't want to make everyone have to figure out how to type "×" to use a stdlib type (to the further dismay of my O-IUF, this is actually a really good argument, especially since a likely use for FSA is in embedded or systems programming, where you might need to use an editor that doesn't support Unicode).

I think another contender might've been "let fsa: [2 of Int]", but if you want a complete list, I'll have to go back and reread the quarter-dozen or so threads on FSAs that pop up whenever we lift the "out of scope" thing (but before they get ruled out of scope again). Semantically speaking, "count * MemoryLayout<Type>.stride" is a pretty much exactly what we're doing at the storage level, so "count * Type" fits well in that regard (IMHO, anyway, since we want the syntax to be concise). It also works as syntactic sugar for declaring homogeneous tuples.

Speaking of which, IIRC, at one point we were considering adding subscripts to tuples and using that for FSAs. I think the hangups were pretty much just that tuples can't conform to protocols and the iffy semantics of subscripting heterogeneous tuples. The former is a bit of a pain point anyway, and unless I've forgotten about some deal-breaker that was brought up in one of those threads, I think it's somewhat likely that we'll eventually do something about it. Unrelated to FSAs and subscripting tuples, we've also discussed variadic generic arguments... My recollection is that there was broad support for the idea; it's just a matter of it being in-scope so that we can figure out the syntax. Once we get that done, if we make tuples extendable we could just say (hand-wavey straw-man syntax, of course):
    extension (Ts: _...) where Ts.count > 0, Ts.reduce(true) { $0 = Ts.Head.self == $1.self } == true {
        subscript(_ i: Int) -> Ts.Head {...}

... and just do it all through tuples. Is this a better than having a dedicated FSA type? Dunno. In large part, it depends on how difficult the various ideas will be to implement, and how useful the extra bits of functionality would be to the rest of the language. Unfortunately, the people who have those answers are busy working with the Swift 4.0 release, and likely don't have time to really weigh in on out of scope topics (which we all agree can be frustrating, but there are practical realities in life, and staying focused enough to meet deadlines is one of theirs).

- Dave Sweeris 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170723/d96f0431/attachment.html>

More information about the swift-evolution mailing list