<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><br></div><div><br>On May 14, 2016, at 9:43 PM, Pyry Jahkola via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><div class="">Tony &amp; Haravikk,</div><div class=""><br class=""></div><div class="">(Reformatting your quoted examples just a bit…)</div><br class=""><div><blockquote type="cite" class=""><blockquote type="cite" class="">It enables things like:<br class=""><font face="Menlo" style="font-size: 11px;" class="">&nbsp; &nbsp; <b class="">func</b> someMethod&lt;S : SequenceType, T&gt;(value: S) -&gt; AnySequence&lt;T&gt;<br class="">&nbsp; &nbsp; &nbsp; &nbsp; <b class="">where</b> S.Generator.Element == T { ... }</font><br class=""></blockquote><br class="">I'm not assuming that. Under the current syntax, I would format your example as:<br class=""><br class=""><font face="Menlo" style="font-size: 11px;" class="">&nbsp; &nbsp; <b class="">func</b> someMethod&lt;<br class="">&nbsp; &nbsp; &nbsp; &nbsp; S : SequenceType, T<br class="">&nbsp; &nbsp; &nbsp; &nbsp; <b class="">where</b> S.Generator.Element == T<br class="">&nbsp; &nbsp; &gt;(value: S) -&gt; AnySequence&lt;T&gt; {<br class="">&nbsp; &nbsp; &nbsp; &nbsp; ...<br class="">&nbsp; &nbsp; }</font><br class=""></blockquote></div><br class=""><div class="">You are both right here, but please note that the proposal still also allows moving <b class="">all</b>&nbsp;constraints to the `<font face="Menlo" class=""><span style="font-size: 11px;" class=""><b class="">where</b></span></font>` clause:</div><div class=""><br class=""></div><div class=""><font face="Menlo" style="font-size: 11px;" class="">&nbsp; &nbsp; <b class="">func</b> someMethod&lt;S, T&gt;(value: S) -&gt; AnySequence&lt;T&gt;</font></div><div class=""><font face="Menlo" style="font-size: 11px;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <b class="">where</b> S : SequenceType,</font></div><div class=""><font face="Menlo" style="font-size: 11px;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; S.Generator.Element == T</font></div><div class=""><font face="Menlo" style="font-size: 11px;" class="">&nbsp; &nbsp; {</font></div><div class=""><font face="Menlo" style="font-size: 11px;" class="">&nbsp; &nbsp; &nbsp; &nbsp; ...</font></div><div class=""><font face="Menlo" style="font-size: 11px;" class="">&nbsp; &nbsp; }</font></div><div class=""><br class=""></div><div class="">just like Swift 2 allows doing so within the `<font face="Menlo" class=""><span style="font-size: 11px;" class="">&lt;...&gt;</span></font>` brackets:</div><div class=""><br class=""></div><div class=""><div class=""><font face="Menlo" style="font-size: 11px;" class="">&nbsp; &nbsp; <b class="">func</b> someMethod&lt;S, T<br class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<b class="">where</b> S : SequenceType, S.Generator.Element == T</font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">&nbsp; &nbsp; &gt;(value: S) -&gt; AnySequence&lt;T&gt; {<br class="">&nbsp; &nbsp; &nbsp; &nbsp; ...<br class="">&nbsp; &nbsp; }</span><br class=""></font></div></div><div class=""><br class=""></div><div class="">The reason I'd recommend that style for anything but simple constraints is because:</div><div class=""><br class=""></div><div class="">1) It makes the call site `<font face="Menlo" class=""><span style="font-size: 11px;" class=""><b class="">let</b> items = someMethod(value: things)</span></font>` lightest to visually match to the declaration, because the only thing between the function name and its argument list is the&nbsp;`<font face="Menlo" class=""><span style="font-size: 11px;" class="">&lt;...&gt;</span></font>`&nbsp;bracketed list of introduced generic types which you'll expect to see in the function signature and constraints.</div><div class=""><br class=""></div><div class="">2) In general, the `<font face="Menlo" class=""><span style="font-size: 11px;" class=""><b class="">where</b></span></font>` constraints really apply to the whole function/type declaration, not just a single generic parameter.</div><div class=""><br class=""></div><div class="">3) It was claimed that all constraints should go right next to the introduction of the generic parameters. But that isn't the whole case because Swift also applies <i class="">implicit</i>&nbsp;constraints onto any generic parameters that are used in constrained positions. If that wasn't clearly said, take the following example in Swift 2.x:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">&nbsp; &nbsp; <b class="">func</b> aMethod&lt;S : SequenceType, T <b class="">where</b> S.Generator.Element == T&gt;(value: S) -&gt; Set&lt;T&gt; {</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <b class="">return</b> Set(value)</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">&nbsp; &nbsp; }</span></font></div><div class=""><br class=""></div><div class="">That declaration actually makes you wait all the way until the return type `<font face="Menlo" class=""><span style="font-size: 11px;" class="">Set&lt;T&gt;</span></font>` until you learn that `<font face="Menlo" style="font-size: 11px;" class="">T</font>` must also necessarily be `<font face="Menlo" style="font-size: 11px;" class="">Hashable</font>`. So I don't see how it's that different if the `<font face="Menlo" class=""><span style="font-size: 11px;" class=""><b class="">where</b></span></font>` clause isn't right next to the generic type arguments' introduction:</div><div class=""><br class=""></div><div class=""><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">&nbsp; &nbsp;&nbsp;<b class="">func</b>&nbsp;</span></font><span style="font-family: Menlo; font-size: 11px;" class="">aMethod</span><font face="Menlo" class=""><span style="font-size: 11px;" class="">&lt;S, T&gt;(value: S) -&gt; Set&lt;T&gt; <font color="#919191" class="">// FWIW, this line contains what I usually have in mind when browsing code.</font></span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <b class="">where</b>&nbsp;<font color="#919191" class="">// T : Hashable, // (implicit)</font></span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; S</span></font><span style="font-family: Menlo; font-size: 11px;" class="">&nbsp;: SequenceType,</span></div><div class=""><span style="font-family: Menlo; font-size: 11px;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; S.Generator.Element == T</span></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">&nbsp; &nbsp; {</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<b class="">return</b>&nbsp;Set(value)</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">&nbsp; &nbsp; }</span></font></div></div><div class=""><br class=""></div><div class="">— Pyry</div><div class=""><br class=""></div></div></blockquote><div><br></div><div>IMHO proposals like this should never be discussed in the context of trivial examples as the full scope of their value gets lost. I have written enough generics code in other languages to appreciate the idea of a 'headline-form-followed-by-the-details-idea' for any complex declaration. My understanding is that the proposal offers to make us write explicitely what anyone reading the code will try to extract out of the declaration. Instead of 100's or 1000's doing the work in their heads, the code author does it once for all subsequent readers. What's not to like about this idea?</div><br><blockquote type="cite"><div><div class="">PS. Besides, neither the original example nor mine was really fair; you don't need `<font face="Menlo" class=""><span style="font-size: 11px;" class=""><b class="">where</b></span></font>` for these. Instead, you'd just write:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">&nbsp; &nbsp; <b class="">func</b> someMethod&lt;S : SequenceType&gt;(value: S) -&gt; AnySequence&lt;S.Generator.Element&gt; {</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">&nbsp; &nbsp; &nbsp; &nbsp; ...</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">&nbsp; &nbsp; }</span></font></div><div class=""><br class=""></div><div class="">which SE-0081 has nothing to argue for or against.</div><div class=""><br class=""></div></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>