<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="">Am 16.05.2016 um 17:04 schrieb Karl via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>>:</div><br class="Apple-interchange-newline"><div class=""><div class=""><blockquote type="cite" class="">internal func _arrayOutOfPlaceReplace<br class=""><B: _ArrayBufferProtocol, C: Collection><br class="">(_ source: inout B, _ bounds: Range<Int>, _ newValues: C, _ insertCount: Int)<br class=""> where<br class=""> C.Iterator.Element == B.Element,<br class=""> B.Index == Int<br class="">{<br class=""><br class="">Now only the relatively unimportant details—that the buffer and collection must have elements of the same type, and that the buffer must have integer indices—are at the end, whereas the basic conformances required to make any sense at all of the declaration are still inline.<br class=""></blockquote><br class="">You see, I’m of the complete opposite opinion - I don’t think those details are “relatively unimportant”; I think they’re absolutely critical.<br class=""><br class="">If you try and call it when your C.Iterator.Element is not equal to B.Element, the function does not exist. You’re talking about some other function in that case, not this one.<br class=""><br class="">Same goes if B.Index is not an Int. If that was an unimportant detail, they would have given ‘bounds’ the type Range<B.Index> and not specified any constraints at all. The function requires the index be an Int - maybe it’s doing some mathematical operations which wouldn’t make sense for a more complex index type, such as DictionaryIndex.<br class=""><br class="">Basically that is it - the ‘where’ clause is a vital part of the function declaration; it defines the specification under which the function exists at all (along with the function name, arguments and return type). If you don’t match every single part of that specification, the type checker won’t match your call to this function - if you don’t meet the constraints, you’re not talking about this function; imagine you have several overloaded function declarations which differ only by ‘where’ condition:<br class=""><br class="">func insert<T>(contentsOf:T) where T:RandomAccessCollection, T.Element == Element<br class="">func insert<T>(contentsOf:T) where T:Collection, T.Element == Element<br class="">func insert<T>(contentsOf:T) where T:Sequence, T.Element == Element<br class="">… etc<br class=""><br class="">the ‘where’ clause isn’t incidental here - it’s the only disambiguating feature between these declarations. I think it’s critical information and shouldn’t be stuffed at the end because you think it’s not important; it is important. If it hinders initial readability of the declaration so much, you can wrap it behind a typealias:<br class=""><br class="">func insert<T: RandomAccessCollectionOf<Element>>(contentsOf: T)<br class="">func insert<T: CollectionOf<Element>>(contentsOf: T)<br class="">func insert<T: SequenceOf<Element>>(contentsOf: T)<br class="">… etc<br class=""></div></div></blockquote><div><br class=""></div>Either you have the constraints first and the parameter list last or the other way around. Fact is that *both* decide whether it is the function you need.</div><div>So just their order cannot help with that.</div><div>I would still argue that the proposed version is more readable: just look at your example above where the first part up to the where is identical at one glance, so that the disambiguating part stands out whereas your other example looks much more unstructured because of the different lengths of the generic type list which makes the congruence of the parameter lists difficult to see because they do not align anymore.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class="">I think that’s much easier to follow, and attempts to reduces the length and verbosity of the where clauses (i.e. like the fact that Collection’s associated type referring to its element is called ‘Element’; ‘CollectionOf’ encodes an equivalent constraint in less characters). This proposal just feels kind of lazy - we’ll just tack them on the end so we can ignore them a bit more easily, even though they’re still going to be monstrously long and difficult-to-read.<br class=""></div></div></blockquote><div><br class=""></div>The typealias idea can be combined with the where clause at the end:</div><div><br class=""></div><div><div class="">func insert<T>(contentsOf:T) where T:RandomAccessCollectionOf<Element><br class="">func insert<T>(contentsOf:T) where T:CollectionOf<Element><br class="">func insert<T>(contentsOf:T) where T:SequenceOf<Element><br class=""></div><div class=""><br class=""></div><div class="">Much easier to discern (at least IMO) because everything is aligned.</div><div class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div class=""><br class="">Are there any other languages that do this? Or anything even similar? It seems to me that the context-switching is something that human beings in general are not going to find very legible; like if you insert too many commas in a sentence.<br class=""></div></div></blockquote><div><br class=""></div>Yes, Ceylon places all constraints (it only knows inheritance constraints) at the end:</div><div><br class=""></div><div><pre data-language="ceylon" class="with-editor" style="background-color: rgb(47, 30, 46); word-wrap: break-word; color: rgb(231, 233, 219); font-family: 'andale mono', 'lucida console', monospace; margin-top: 0px; margin-bottom: 0px; padding: 10px; border: 0px; font-size: 15px; vertical-align: baseline; line-height: 1.5;"><code class="rainbow" style="font-family: Inconsolata, Monaco, Courier, monospace; margin: 0px; padding: 0px; border: 0px; font-size: 14.5px; vertical-align: baseline; line-height: 1.5;"><span class="entity function" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(6, 182, 239);">shared</span> <span class="entity class" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(254, 196, 24);">Value</span> <span class="global variable" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(239, 97, 85);">sum</span><<span class="entity class" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(254, 196, 24);">Value</span>>({<span class="entity class" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(254, 196, 24);">Value</span>+} <span class="global variable" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(239, 97, 85);">values</span>)
<span class="keyword" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(184, 186, 175);">given</span> <span class="entity class" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(254, 196, 24);">Value</span> <span class="keyword" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(184, 186, 175);">satisfies</span> <span class="entity class" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(254, 196, 24);">Summable</span><<span class="entity class" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(254, 196, 24);">Value</span>> { ... }</code></pre></div><div><pre data-language="ceylon" class="with-editor" style="background-color: rgb(47, 30, 46); word-wrap: break-word; color: rgb(231, 233, 219); font-family: 'andale mono', 'lucida console', monospace; margin-top: 0px; margin-bottom: 0px; padding: 10px; border: 0px; font-size: 15px; vertical-align: baseline; line-height: 1.5;"><code class="rainbow" style="font-family: Inconsolata, Monaco, Courier, monospace; margin: 0px; padding: 0px; border: 0px; font-size: 14.5px; vertical-align: baseline; line-height: 1.5;"><span class="entity function" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(6, 182, 239);">shared</span> <<span class="entity class" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(254, 196, 24);">Key</span>-><span class="entity class" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(254, 196, 24);">Item</span>>[] <span class="global variable" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(239, 97, 85);">zip</span><<span class="entity class" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(254, 196, 24);">Key</span>,<span class="entity class" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(254, 196, 24);">Item</span>>({<span class="entity class" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(254, 196, 24);">Key</span>*} <span class="global variable" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(239, 97, 85);">keys</span>, {<span class="entity class" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(254, 196, 24);">Item</span>*} <span class="global variable" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(239, 97, 85);">items</span>)
<span class="keyword" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(184, 186, 175);">given</span> <span class="entity class" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(254, 196, 24);">Key</span> <span class="keyword" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(184, 186, 175);">satisfies</span> <span class="entity class" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(254, 196, 24);">Object</span>
<span class="keyword" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(184, 186, 175);">given</span> <span class="entity class" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(254, 196, 24);">Item</span> <span class="keyword" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(184, 186, 175);">satisfies</span> <span class="entity class" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(254, 196, 24);">Object</span> { ... }</code></pre><div class=""><br class=""></div><div class="">It does the same for type definitions:</div><div class=""><pre data-language="ceylon" class="with-editor" style="background-color: rgb(47, 30, 46); word-wrap: break-word; color: rgb(231, 233, 219); font-family: 'andale mono', 'lucida console', monospace; margin-top: 0px; margin-bottom: 0px; padding: 10px; border: 0px; font-size: 15px; vertical-align: baseline; line-height: 1.5;"><code class="rainbow" style="font-family: Inconsolata, Monaco, Courier, monospace; margin: 0px; padding: 0px; border: 0px; font-size: 14.5px; vertical-align: baseline; line-height: 1.5;"><span class="entity function" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(6, 182, 239);">shared</span> <span class="keyword" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(184, 186, 175);">class</span> <span class="entity class" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(254, 196, 24);">Singleton</span><<span class="keyword" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(184, 186, 175);">out</span> <span class="entity class" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(254, 196, 24);">Element</span>>(<span class="entity class" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(254, 196, 24);">Element</span> <span class="global variable" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(239, 97, 85);">element</span>)
<span class="keyword" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(184, 186, 175);">extends</span> <span class="entity class" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(254, 196, 24);">Object</span>()
<span class="keyword" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(184, 186, 175);">satisfies</span> [<span class="entity class" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(254, 196, 24);">Element</span>+]
<span class="keyword" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(184, 186, 175);">given</span> <span class="entity class" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(254, 196, 24);">Element</span> <span class="keyword" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(184, 186, 175);">satisfies</span> <span class="entity class" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; color: rgb(254, 196, 24);">Object</span> { ... }</code></pre><div class=""><br class=""></div></div><div class="">-Thorsten</div></div><div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class=""><blockquote type="cite" class="">On 15 May 2016, at 16:05, Brent Royal-Gordon via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class=""><blockquote type="cite" class="">There we are. I read the declaration of the function from beginning to end<br class="">and gradually formed a rough understanding of it without needing to change<br class="">my expectations halfway through. I still have doubts about 'insertCount',<br class="">but I was at least able to formulate an hypothesis about its use.<br class=""><br class="">YMMV, but as far as I'm concerned, the original declaration was much easier<br class="">to understand.<br class=""></blockquote><br class="">I actually agree with you for this case, but not *all* type information *has* to be moved to the end. Try this on for size, which is actually still the most natural way to write this declaration in SE-0081:<br class=""><br class=""><br class="">This proposal *permits* you to hollow out the generic parameter list to the point of vacuousness, but that doesn't mean it's the right thing to do. It might make sense to ban a direct `X: Foo` requirement unless there was already an `X: Bar` in the generic parameter list. Or we might simply need to paraphrase the Perl manual page: "There are several ways to write a generic requirement, so consider picking the most readable one."<br class=""><br class="">-- <br class="">Brent Royal-Gordon<br class="">Architechies<br class=""><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></blockquote><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></div></blockquote></div><br class=""></body></html>