<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On 27 Jan 2017, at 22:25, Slava Pestov <<a href="mailto:spestov@apple.com" class="">spestov@apple.com</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=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 27, 2017, at 11:44 AM, 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="">So, 2 quick points:<br class=""><div class=""><br class=""></div><div class="">1) I have often wanted a shorthand for expressing long tuples; I definitely think that’s something worth bike-shedding, e.g. - <font face="Courier" class="">(String * 4, Int32 * 4)</font> or something</div></div></div></blockquote><div class=""><br class=""></div>Why not define a struct, or a tuple consisting of two arrays?</div></div></div></blockquote><div><br class=""></div>Because I want a fixed-length guarantee; <font face="Courier" class="">([String], [Int])</font> could have any number of Strings or Ints.</div><div>It’s just a shorthand for defining long or complex tuples; we currently import C arrays as massive tuples which can be basically impossible to read.</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=""><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="">2) Having a special non-growing array type which is called “array” and separate from <font face="Courier" class="">Array<T></font> is not such a good idea IMO. I would rather allow tuples to conform to protocols (see: <a href="https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md#extensions-of-structural-types" class="">https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md#extensions-of-structural-types</a>).</div><div class=""><br class=""></div><div class="">If tuples could conform to protocols, we could say “any tuple of homogenous elements is a <font face="Courier" class="">Collection</font>”. There would be benefits for the standard library, too - <font face="Courier" class="">EmptyCollection<T></font> would disappear, replaced with the empty tuple <font face="Courier" class="">()</font>,</div></div></div></blockquote><div class=""><br class=""></div>This sounds too clever.</div></div></div></blockquote><div><br class=""></div><div>Yeah… the cleverness is one of things I <i class="">like</i> about it. We get to remove these canned conformances and reduce the stdlib surface area while gaining an efficient way to express a fixed-size Collection. It would come with all kinds of supplementary benefits, such as iterating and mapping the elements of a tuple.</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=""><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=""> as would <font face="Courier" class="">CollectionOfOne<T></font>, to be replaced by a single-element tuple <font face="Courier" class="">(T)</font>.</div></div></div></blockquote><div class=""><br class=""></div><div class="">For what it’s worth, Swift doesn’t have single-element tuples. (T) is just sugar for the type T itself.</div></div></div></div></blockquote><div><br class=""></div><div>Would it be unreasonable to separate those, so that (T) is separate from T instead of being a synonym for it? There is some awkwardness with tuples due to legacy designs. Perhaps this would help clean it up a little (or perhaps make it worse, who knows?)</div><div><br class=""></div><div>For source compatibility, we could allow an implicit conversion; in the same way that a T can be implicitly “promoted" to an Optional<T>, it could be implicitly “promoted” to a single-element tuple of T (and vice-versa).</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><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=""> We would also be able to remove our limited-arity <font face="Courier" class="">==</font> overloads in favour of actual, honest-to-goodness <font face="Courier" class="">Equatable</font> conformance.</div></div></div></blockquote><div class=""><br class=""></div>I like this idea though.</div><div class=""><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=""><br class=""></div><div class="">- Karl</div><a href="https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md#extensions-of-structural-types" class=""></a></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></body></html>