<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class="">On Aug 3, 2017, at 12:45 AM, Daryle Walker <<a href="mailto:darylew@mac.com" class="">darylew@mac.com</a>> wrote:</div><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div class="">On Aug 2, 2017, at 4:44 PM, Karl Wagner via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I’m -1 on adding a fixed-sized Array type.<div class=""><br class=""></div><div class="">It goes back to something which I remember reading from John McCall earlier this week but can’t find any more: about tuple indices being nominal and not ordinal. How do fixed-size Arrays differ? Are their indexes truly not nominal?</div></div></div></blockquote><div class=""><br class=""></div><div class="">I think he meant that the numbered names for tuple members were originally (?) there because the Swift authors didn’t mandate each member needing a label, so there needed some way to refer to unnamed members. Note that numbered names are not true integer variables, not even useable as such. Array indexes are programmable objects; algorithms on the indexes is how we select array subsets to apply algorithms on.</div></div></div></div></blockquote><div><br class=""></div>Yes, essentially. I was making this argument on a slightly higher level, just thinking about the meaning of values separate from any syntax.</div><div><br class=""></div><div>A fixed-sized array is still fundamentally an array: it's a sequence of homogenous elements, where relative positions generally have some level of meaning. In an array like [A,B,C,D], it's probably *significant* that A comes first and that C comes before D. On some level, if it wasn't true that the order was significant, it wouldn't "really" be an array, it would be a set (or multiset) being represented using an array.</div><div><br class=""></div><div>In contrast, a tuple is more like a jumble of independent values, ordered only because in this benighted world we can't really write them down at the same time. If you know someone's name and age, and you have to scribble them both down on a piece of paper, it doesn't really change anything which one you write first. At most there's some arbitrary convention for the order, like putting x before y in Cartesian coordinates.</div><div><br class=""></div><div>We can choose different types for different purposes because they convey different things about the values they store. Isomorphism is not meaning.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">The difference between a fixed-size array and the dynamically-sized Array we already have is that the programmer expects specific data at each element. Maybe it’s elements of a vector or matrix, or some other structure, but in general I think that constraints about the size/shape of the sequence implies expectations about what you’re going to find at each location. Maybe you would normally write a struct for it, but it’s not worth writing out. In that sense, how is it different from a homogenous tuple?</div></div></div></blockquote><div class=""><br class=""></div><div class="">I’m not sure what you mean here. How do elements of dynamically-sized arrays not have expectations?</div><div class=""><br class=""></div><div class="">The big innovation arrays (and loops) brought was no longer having a per-sub-object declaration/command for elements. Just tweak a number.</div><div class=""><br class=""></div><div class="">I’m not good at explicit explanations, so having to justify adding a type that’s been around for a long time (at least FORTRAN 4+ decades ago) an almost every systems programming language has is frustrating. I thought the desire would be obvious; if there were FSAs in Swift 1, would there be any “just slap Collection on tuples and be done with it” suggestions now? It doesn’t help that I still don’t know why FSAs where skipped in Swift 1; did they forget or was there some high-level type-theory reason? (Were the type description records in the Swift ABI too fragile for a type that wouldn’t have per-sub-object entries (assuming theoretical Swift-1-FSAs weren’t translated to massive homogenous tuples)?)</div></div></div></div></blockquote><div><br class=""></div>They just weren't a priority. There are many things I wish we had done more work on before we released Swift 1, but trying to perfectly represent everything in C type system is not one of them.</div><div><br class=""></div><div>Reasons not to prioritize fixed-sized arrays:</div><div>1. Variably-sized arrays are a much more important data structure. Fixed sized arrays are easier to make perform well, but they are inflexible and only narrowly useful.</div><div>2. The bound introduces significant expressional complexity to the type system. What types are eligible as bounds? What sorts of inference and meta-programming are possible on bounds? etc.</div><div>3. The language/library interactions are complex. It's a general data structure that demands proper integration with the rest of the collections library, but the language also really needs to hard-code an exact representation. So it would take a lot of work to integrate.</div><div><br class=""></div><div>Honestly, a lot of this still applies. I would like to see fixed-sized arrays in the language eventually, but they are not going to become a priority, because there's a lot of other stuff that is more important to work on.</div><div><br class=""></div><div>John.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class=""><br class=""></div><div class="">I mentioned in my proposal that no language (that I know of) splatted tuple and array syntax together, either declaration syntax or dereferencing syntax. (Lua has shared dereferencing syntax, but they both rip-off dictionaries.) Where do people think every one else over the last few decades went wrong?</div><div class=""><br class=""></div><div class="">Maybe there’s a copy of the FORTRAN design documents out there?...</div><div class=""><br class=""></div><blockquote type="cite" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Also, what effect would this have on Array as the common-currency for simple lists? And what about the literals - does [myObj, anotherObj] give you a [MyObject] or a [2; MyObject]? Is that what users will intuitively expect? What about if it’s a “let” constant?</div></div></blockquote><div class=""><br class=""></div><div class="">Later revisions of the proposal have a distinct grid literal syntax, to clear up any potential confusion. The standard array literals would map to Array. The grid literal, which includes the dimensions of the array before a list of each value, would map to a fixed-size array.</div><div class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">So overall, I’m unconvinced of the need for fixed-size arrays. My counter-proposal would be a shorthand syntax for more conveniently defining homogenous tuples, and keep them as our go-to objects for ad-hoc groups of things. That’s it. If you would have used a fixed-size Array in C, keep using homogenous tuples in Swift.</div><div class=""><br class=""></div><div class="">As for the part about the @vector and @parallel attributes, those would be worth a separate proposal. As for @parallel, I suggested something like that before but Dave Abrahams said any such support would look more like a generic concurrent wrapper, e.g. <a href="https://gist.github.com/karwa/43ae838809cc68d317003f2885c71572" class="">https://gist.github.com/karwa/43ae838809cc68d317003f2885c71572</a>. Vector support is worth thinking about in a separate proposal.</div></div></div></blockquote><br class=""></div><div class="">A main point for my FSA design is that I want to allow the default iteration primitive (for-loop) to have a vectorized/parallel implementation (someday). Since Sequence/Collection always has a sequential traversal policy (It’s in the name!), it’s the main reason FSA don’t directly conform to Collection in the design.</div><div class=""><br class=""></div><div class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">— </div><div class="">Daryle Walker<br class="">Mac, Internet, and Video Game Junkie<br class="">darylew AT mac DOT com </div></div></div><br class=""><div class=""><blockquote type="cite" class=""></blockquote></div></div></div></div></blockquote></div><br class=""></body></html>