<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="">+1. &nbsp;Nesting protocols inside an “owning" type and importing prefixed Objective-C protocols this way would be great!<div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 17, 2017, at 6:15 PM, T.J. Usiyan via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">+1 to all of that. The proposal in general and the import rule.</div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Tue, Jan 17, 2017 at 7:07 PM, Douglas Gregor via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class=""><div class="h5"><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Nov 5, 2016, at 2:44 AM, Karl via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="m_-312512682317316134Apple-interchange-newline"><div class=""><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><blockquote type="cite" class=""><div class=""><br class="m_-312512682317316134Apple-interchange-newline">On 2 Nov 2016, at 20:54, Slava Pestov &lt;<a href="mailto:spestov@apple.com" target="_blank" class="">spestov@apple.com</a>&gt; wrote:</div><br class="m_-312512682317316134Apple-interchange-newline"><div class=""><blockquote type="cite" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><br class="m_-312512682317316134Apple-interchange-newline">On Nov 2, 2016, at 8:32 AM, Paul Cantrell &lt;<a href="mailto:cantrell@pobox.com" target="_blank" class="">cantrell@pobox.com</a>&gt; wrote:<br class=""><br class=""><br class=""><blockquote type="cite" class="">On Oct 24, 2016, at 4:43 PM, Slava Pestov &lt;<a href="mailto:spestov@apple.com" target="_blank" class="">spestov@apple.com</a>&gt; wrote:<br class=""><br class=""><br class=""><blockquote type="cite" class="">On Oct 24, 2016, at 8:12 AM, Paul Cantrell &lt;<a href="mailto:cantrell@pobox.com" target="_blank" class="">cantrell@pobox.com</a>&gt; wrote:<br class=""><br class=""><br class=""><blockquote type="cite" class="">On Oct 24, 2016, at 5:09 AM, Slava Pestov via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class="">However protocols nested inside types and types nested inside protocols is still not supported, because protocols introduce a separate series of issues involving associated types and the ’Self’ type.<br class=""><br class="">The hard part of getting nested generics right is what to do if a nested type ‘captures’ generic parameters of the outer type. For non-protocol types, the behavior here is pretty straightforward.<br class=""><br class="">If we allow protocols to be nested inside other types, we have to decide what to do if the protocol ‘closes over’ generic parameters of the outer type. For example,<br class=""><br class="">struct A&lt;T&gt; {<br class="">protocol P {<br class="">func requirement() -&gt; T<br class="">}<br class="">}<br class=""><br class="">Presumably A&lt;Int&gt;.P and A&lt;String&gt;.P are distinct types, and A.P has a hidden associated type corresponding to the type parameter ’T’?<br class=""><br class="">The other case is problematic too — the nested type might refer to an associated type of the outer protocol:<br class=""><br class="">protocol P {<br class="">associatedtype A<br class=""><br class="">struct T {<br class="">var value: A<br class="">}<br class="">}<br class=""><br class="">Now writing P.T does not make sense, for the same reason that we cannot form an existential of type P.A. We could prohibit references to outer associated types of this form, or we could figure out some way to give it a meaning. If C is a concrete type conforming to P, then certainly C.T makes sense, for instance. Internally, the nested type A.T could have a hidden ‘Self’ generic type parameter, so that writing C.T is really the same as P.T&lt;C&gt;.<br class=""><br class="">Protocols nested inside protocols also have the same issue.<br class=""></blockquote><br class="">FWIW, in almost all the situations where I’ve wanted to nest types inside protocols and generic types, it’s only as a namespacing convenience. Most often, it’s an enum type that’s used only by a single method, and having it at the top of the module namespace adds clutter.<br class=""><br class="">Here’s a real life example pared down. I wish I could do this:<br class=""><br class="">public struct ResponseContentTransformer&lt;<wbr class="">InputContentType, OutputContentType&gt;: ResponseTransformer {<br class=""><br class="">&nbsp;&nbsp;public init(onInputTypeMismatch mismatchAction: InputTypeMismatchAction = .error) {<br class="">&nbsp;&nbsp;&nbsp;&nbsp;...<br class="">&nbsp;&nbsp;}<br class=""><br class="">&nbsp;&nbsp;public enum InputTypeMismatchAction { &nbsp;// Does not depend on generic types above<br class="">&nbsp;&nbsp;&nbsp;&nbsp;case error<br class="">&nbsp;&nbsp;&nbsp;&nbsp;case skip<br class="">&nbsp;&nbsp;&nbsp;&nbsp;case skipIfOutputTypeMatches<br class="">&nbsp;&nbsp;}<br class=""><br class="">}<br class=""><br class="">InputTypeMismatchAction is tightly associated with ResponseContentTransformer, and is confusing as a top-level type.<br class=""><br class="">What do you think about providing a “no captures” modifier for nested types — like static inner classes in Java? Then Swift could provide the namespace nesting I wish for this without having to resolve the trickier type capture questions yet.<br class=""><br class="">Alternatively, what if (1) outer types aren’t capture unless they’re referenced, and (2) nesting is only illegal if there’s a capture? Then my code above would compile, as would this:<br class=""><br class="">public struct S&lt;T&gt; {<br class="">&nbsp;&nbsp;public enum Foo {<br class="">&nbsp;&nbsp;&nbsp;&nbsp;case yin<br class="">&nbsp;&nbsp;&nbsp;&nbsp;case yang<br class="">&nbsp;&nbsp;}<br class="">}<br class=""><br class="">…but this wouldn’t:<br class=""><br class="">public struct S&lt;T&gt; {<br class="">&nbsp;&nbsp;public enum Foo {<br class="">&nbsp;&nbsp;&nbsp;&nbsp;case yin(thing: T) &nbsp;// capture of T illegal (for now)<br class="">&nbsp;&nbsp;&nbsp;&nbsp;case yang<br class="">&nbsp;&nbsp;}<br class="">}<br class=""><br class="">Either of these approaches would allow hygienic namespacing now while leaving the door open to outer type capture in the future.<br class=""></blockquote><br class="">Yeah, this makes sense for a first cut at this feature.<br class=""><br class="">Slava<br class=""></blockquote><br class="">Should I take a crack at writing up a proposal for this? Now? After ABI work is done? (Probably the latter “OK if no captures” approach?) Eager to help; don’t want to be in the way.<br class=""></blockquote><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important" class="">Just speaking for myself and not the whole team — I think you can submit the proposal at any time, we’re unlikely to get around to doing it, if you want to take a crack that would be great (again, with ‘no captures’ it’s “trivial”).</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important" class="">Slava</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><blockquote type="cite" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><br class="">P</blockquote></div></blockquote></div><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><br class=""></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="">Sorry, let this slip. Proposal sent -&nbsp;<a href="https://github.com/apple/swift-evolution/pull/552" target="_blank" class="">https://github.com/apple/<wbr class="">swift-evolution/pull/552</a></div></div></blockquote><br class=""></div></div></div><div class="">(Coming back to this after a very long time)</div><div class=""><br class=""></div><div class="">One very high-level comment: one of your early examples is making the Delegate of a view. Did you consider making this an Objective-C translation rule as well, so that *Delegate and *DataSource protocols would be imported as nested types within a class with the name signified by *, e.g.,&nbsp;</div><div class=""><br class=""></div><div class=""><font face="Menlo" class=""><span class="m_-312512682317316134Apple-tab-span" style="white-space:pre-wrap">        </span>class UITableView {</font></div><div class=""><font face="Menlo" class=""><span class="m_-312512682317316134Apple-tab-span" style="white-space:pre-wrap">        </span>&nbsp; @objc(UITableViewDataSource)</font></div><div class=""><font face="Menlo" class=""><span class="m_-312512682317316134Apple-tab-span" style="white-space:pre-wrap">        </span>&nbsp; protocol DataSource { … }</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class=""><span class="m_-312512682317316134Apple-tab-span" style="white-space:pre-wrap">        </span>&nbsp; @objc(UITableViewDelegate)</font></div><div class=""><font face="Menlo" class=""><span class="m_-312512682317316134Apple-tab-span" style="white-space:pre-wrap">        </span>&nbsp; protocol Delegate { … }</font></div><div class=""><font face="Menlo" class=""><span class="m_-312512682317316134Apple-tab-span" style="white-space:pre-wrap">        </span>}</font></div><div class=""><br class=""></div><div class=""><span class="m_-312512682317316134Apple-tab-span" style="white-space:pre-wrap">        </span>- Doug</div><div class=""><br class=""></div><br class=""></div><br class="">______________________________<wbr class="">_________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-<wbr class="">evolution</a><br class="">
<br class=""></blockquote></div><br class=""></div>
_______________________________________________<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></blockquote></div><br class=""></div></body></html>