<div dir="ltr">You&#39;re right and since you can&#39;t nest any kind of type in a generic type right, that wouldn&#39;t work even with this proposal. However, in the generics manifesto they did say that they intend to remove that restriction. If they do lift the restriction, they may have to leave an exception in place for protocols.</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 28, 2016 at 5:27 PM, Douglas Gregor <span dir="ltr">&lt;<a href="mailto:dgregor@apple.com" target="_blank">dgregor@apple.com</a>&gt;</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"><span class=""><br><div><blockquote type="cite"><div>On Apr 28, 2016, at 10:15 AM, Brad Hilton via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><div style="word-wrap:break-word">Type nesting allows some convenient and straightforward semantics that we see inside the Swift standard library such as views on String like String.CharacterView, String.UnicodeScalarView, etc. However a protocol cannot be nested in a type and gives a non-obvious error that the “Declaration is only valid at file scope.” Just as other nested types allow proper contextual scoping, a nested protocol could make a lot sense for a number of patterns. For example, there are many “Delegate” protocols throughout the Cocoa frameworks. Here’s a controller/delegate pattern before and after type nesting:<div><div><br></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><div style="margin:0px;line-height:normal;color:rgb(0,132,0)"><span>// Without type nesting</span></div><div style="margin:0px;line-height:normal;color:rgb(0,132,0)"><span><br></span></div><div style="margin:0px;line-height:normal"><span style="color:#bb2ca2">protocol</span><span> MyControllerDelegate : </span><span style="color:#bb2ca2">class</span><span> {</span></div><div style="margin:0px;line-height:normal;min-height:14px"><span>    </span><br></div><div style="margin:0px;line-height:normal"><span>}</span></div><div style="margin:0px;line-height:normal;min-height:14px"><span></span><br></div><div style="margin:0px;line-height:normal"><span style="color:#bb2ca2">class</span><span> MyController {</span></div><div style="margin:0px;line-height:normal;min-height:14px"><span>    </span><br></div><div style="margin:0px;line-height:normal;color:rgb(79,129,135)"><span>    </span><span style="color:#bb2ca2">weak</span><span> </span><span style="color:#bb2ca2">var</span><span> delegate: </span><span>MyControllerDelegate</span><span>?</span></div><div style="margin:0px;line-height:normal;min-height:14px"><span>    </span><br></div><div style="margin:0px;line-height:normal"><span>}</span></div><div style="margin:0px;line-height:normal;min-height:14px"><span></span><br></div><div style="margin:0px;line-height:normal;color:rgb(0,132,0)"><span>// With type nesting</span></div><div style="margin:0px;line-height:normal;color:rgb(0,132,0)"><span><br></span></div><div style="margin:0px;line-height:normal"><span style="color:#bb2ca2">class</span><span> MyController {</span></div><div style="margin:0px;line-height:normal;min-height:14px"><span>    </span><br></div><div style="margin:0px;line-height:normal"><span>    </span><span style="color:#bb2ca2">weak</span><span> </span><span style="color:#bb2ca2">var</span><span> delegate: </span><span style="color:#4f8187">Delegate</span><span>?</span></div><div style="margin:0px;line-height:normal;min-height:14px"><span>    </span><br></div><div style="margin:0px;line-height:normal"><span>    </span><span style="color:#bb2ca2">protocol</span><span> Delegate : </span><span style="color:#bb2ca2">class</span><span> {</span></div><div style="margin:0px;line-height:normal;min-height:14px"><span>        </span><br></div><div style="margin:0px;line-height:normal"><span>    }</span></div><div style="margin:0px;line-height:normal;min-height:14px"><span>    </span><br></div><div style="margin:0px;line-height:normal"><span>}</span></div><div style="margin:0px;line-height:normal"><br></div><div style="margin:0px;line-height:normal"><span style="font-family:Helvetica">Though the change is mostly semantics, it does allow an explicit association between My Controller and the Delegate instead of only a named association. It also cleans up the module name space like other nested types and makes associated protocols more discoverable in my opinion. </span></div><div style="margin:0px;line-height:normal"><span style="font-family:Helvetica"><br></span></div><div style="margin:0px;line-height:normal"><span style="font-family:Helvetica">I’d love to hear everyone’s thoughts.</span></div></div></div></div></div></div></blockquote><br></div></span><div>Note that this cannot work when any enclosing type is generic, e.g.,</div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font face="Menlo">class MyController&lt;T&gt; {</font></div><div><font face="Menlo">  protocol Delegate {</font></div><div><font face="Menlo">    // I’ve just created a parameterized protocol!</font></div><div><font face="Menlo">  }</font></div><div><font face="Menlo">}</font></div></blockquote><div><br></div><div>Otherwise, I don’t see any issues with the proposal, and I like that it eliminates a large number of top-level names.</div><div><br></div><div><span style="white-space:pre-wrap">        </span>- Doug</div><div><br></div><br></div></blockquote></div><br></div>