<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><br><br>Sent from my iPhone</div><div><br>On Nov 13, 2016, at 4:03 PM, Austin Zheng &lt;<a href="mailto:austinzheng@gmail.com">austinzheng@gmail.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">I'd be happy to put something together, unless someone else wants to take it on.</div></div></blockquote><div><br></div>Great, thanks!<div><br><blockquote type="cite"><div><div dir="ltr"><div><br></div><div>Doug, I also owe you a PR adding a minor amendment to one of the accepted proposals. I'll get to that this week.</div></div></div></blockquote><div><br></div>Sounds great.&nbsp;</div><div><br></div><div>&nbsp; - Doug</div><div><br><blockquote type="cite"><div><div dir="ltr"><div><div>Austin</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Nov 13, 2016 at 10:13 PM, Douglas Gregor via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>Recursive protocol constraints is one small-looking feature that could greatly improve the standard library. The generics manifesto describes it this way:</div><div><br></div><div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px"><span style="background-color:rgba(255,255,255,0)">"Currently, an associated type cannot be required to conform to its enclosing protocol (or any protocol that inherits that protocol). For example, in the standard library&nbsp;<code style="box-sizing:border-box;padding:0.2em 0px;margin:0px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">SubSequence</code>&nbsp;type of a&nbsp;<code style="box-sizing:border-box;padding:0.2em 0px;margin:0px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">Sequence</code>&nbsp;should itself be a&nbsp;<code style="box-sizing:border-box;padding:0.2em 0px;margin:0px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">Sequence</code>:</span></p><div class="m_2981084392784924051highlight m_2981084392784924051highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px"><pre style="box-sizing:border-box;word-wrap:normal;margin-top:0px;margin-bottom:0px;padding:16px;overflow:auto;line-height:1.45;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal"><font face="UICTFontTextStyleBody"><span style="white-space:normal;background-color:rgba(255,255,255,0)"><span class="m_2981084392784924051pl-k" style="box-sizing:border-box">protocol</span> <span class="m_2981084392784924051pl-en" style="box-sizing:border-box">Sequence</span> {
  <span class="m_2981084392784924051pl-k" style="box-sizing:border-box">associatedtype</span> <span class="m_2981084392784924051pl-v" style="box-sizing:border-box">Iterator</span> : <span class="m_2981084392784924051pl-e" style="box-sizing:border-box"><span class="m_2981084392784924051pl-c1" style="box-sizing:border-box">IteratorProtocol</span></span>
  ...
  <span class="m_2981084392784924051pl-k" style="box-sizing:border-box">associatedtype</span> <span class="m_2981084392784924051pl-v" style="box-sizing:border-box">SubSequence</span> : <span class="m_2981084392784924051pl-e" style="box-sizing:border-box"><span class="m_2981084392784924051pl-c1" style="box-sizing:border-box">Sequence</span>   <span class="m_2981084392784924051pl-c" style="box-sizing:border-box">// currently ill-formed, but should be possible</span></span>
<span class="m_2981084392784924051pl-e" style="box-sizing:border-box"><span class="m_2981084392784924051pl-c" style="box-sizing:border-box"></span></span>}</span></font></pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px"><span style="background-color:rgba(255,255,255,0)">The compiler currently rejects this protocol, which is unfortunate: it effectively pushes the&nbsp;<code style="box-sizing:border-box;padding:0.2em 0px;margin:0px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">SubSequence</code>-must-be-a-<code style="box-sizing:border-box;padding:0.2em 0px;margin:0px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">Sequ<wbr>ence</code>&nbsp;requirement into every consumer of&nbsp;<code style="box-sizing:border-box;padding:0.2em 0px;margin:0px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">SubSequence</code>, and does not communicate the intent of this abstraction well."</span></p><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25"><a id="m_2981084392784924051user-content-nested-generics" class="m_2981084392784924051anchor" href="https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md#nested-generics" style="box-sizing:border-box;text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u></u><u></u><font color="#000000" size="3"><span style="background-color:rgba(255,255,255,0)"><u></u><u></u></span></font></a></h3>It's actually slightly worse than the above implies: the standard library has a pile of underscore-prefixed protocols (e.g., _Sequence) specifically to dodge this restriction. They are ugly, and we want them to go away. Many of these places are marked with an ABI FIXME in the standard library sources.&nbsp;</div><div><br></div><div>Would someone like to write up a proposal for this feature? The syntax and basic semantics are pretty direct, but a proposal should also capture the expected effects on the standard library, particularly when combined with where clauses on associated types.</div><div><br></div><div>I also have a nagging feeling that we will need some form of restrictions on this feature for implementation reasons, e.g., because some recursive constraints will form unsolvable systems.</div><div><br></div><div>For reference, we've already been implementing this feature. Some information about the compiler internal issues is captured at:</div><div><br></div><div>&nbsp;&nbsp;<a href="https://gist.github.com/DougGregor/e7c4e7bb4465d6f5fa2b59be72dbdba6" target="_blank">https://gist.github.com/<wbr>DougGregor/<wbr>e7c4e7bb4465d6f5fa2b59be72dbdb<wbr>a6</a></div><div><br></div><div>&nbsp; - Doug</div><div><br></div><div><br></div><div><br><div>Sent from my iPhone</div></div></div><br>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
<br></blockquote></div><br></div>
</div></blockquote></div></body></html>