<div dir="ltr">I like it!<div><br></div><div>I haven’t thought through the ramifications regarding associated types yet though.</div><div><br></div><div>Is your vision that each conforming type would have to provide its own nested type as specified by the protocol?</div><div><br></div><div>Or could the protocol itself define a nested type and anything could use it?</div><div><br></div><div>protocol FloatingPoint: … {</div><div> enum RoundingRule {</div><div> // Do I put an implementation here?</div><div> }</div><div>}<br><div><br></div><div>Nevin</div><div><br></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 17, 2016 at 1:59 PM, Karl via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">I was just doing some googling, turns out there was a discussion about nesting protocols in other types that seemed to go positively a long time ago: <a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160425/016074.html" target="_blank">https://lists.swift.org/<wbr>pipermail/swift-evolution/<wbr>Week-of-Mon-20160425/016074.<wbr>html</a><div><br></div><div>I would additionally like to propose that protocols be allowed to contain nested types (including other protocols). Relevant ABI issue is that the standard library contains enums for “FloatingPointRoundingRule”, “FloatingPointClassification” and “FloatingPointSign”. They would probably be better expressed as “FloatingPoint.RoundingRule”, “.Sign", etc.</div><div><br></div><div>so to summarise, newly legal would be:</div><div><br></div><div>class MyClass {</div><div><br></div><div> protocol Delegate {</div><div> }</div><div>}</div><div><br></div><div>and also:</div><div><br></div><div>protocol MyProto {</div><div><br></div><div> enum SomeValue {</div><div> }</div><div><br></div><div> protocol Delegate {</div><div> associatedType ExpectedContent</div><div><br></div><div><span class="m_4845095118596932916Apple-tab-span" style="white-space:pre-wrap">        </span>func receive(_: ExpectedContent, for: SomeValue)</div><div><br></div><div> protocol SecondaryTarget {</div><div> func receive(_ : ExpectedContent)</div><div> }</div><div> }</div><div>}</div><div><br></div><div>When conforming to a nested protocol, you can just use the name of the protocol:</div><div><br></div><div>class Host : MyProto.Delegate {</div><div>}</div><div><br></div><div>Except if a protocol in the chain has associated types, then you must use a concrete, conforming type instead (as you would in the first example — MyClass.Delegate):</div><div><br></div><div>class SecondaryProcessor : Host.SecondaryTarget {</div><div>}</div><div><br></div><div>If we’re good with this, I’ll write up a proposal.</div><span class="HOEnZb"><font color="#888888"><div><div><div><br></div><div>- Karl</div></div></div></font></span></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>