<div dir="ltr">+1 to all of that. The proposal in general and the import rule.</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 17, 2017 at 7:07 PM, Douglas Gregor 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"><div><div class="h5"><br><div><blockquote type="cite"><div>On Nov 5, 2016, at 2:44 AM, Karl via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br class="m_-312512682317316134Apple-interchange-newline"><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"><blockquote type="cite"><div><br class="m_-312512682317316134Apple-interchange-newline">On 2 Nov 2016, at 20:54, Slava Pestov <<a href="mailto:spestov@apple.com" target="_blank">spestov@apple.com</a>> wrote:</div><br class="m_-312512682317316134Apple-interchange-newline"><div><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"><br class="m_-312512682317316134Apple-interchange-newline">On Nov 2, 2016, at 8:32 AM, Paul Cantrell <<a href="mailto:cantrell@pobox.com" target="_blank">cantrell@pobox.com</a>> wrote:<br><br><br><blockquote type="cite">On Oct 24, 2016, at 4:43 PM, Slava Pestov <<a href="mailto:spestov@apple.com" target="_blank">spestov@apple.com</a>> wrote:<br><br><br><blockquote type="cite">On Oct 24, 2016, at 8:12 AM, Paul Cantrell <<a href="mailto:cantrell@pobox.com" target="_blank">cantrell@pobox.com</a>> wrote:<br><br><br><blockquote type="cite">On Oct 24, 2016, at 5:09 AM, Slava Pestov via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br><br>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><br>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><br>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><br>struct A<T> {<br>protocol P {<br>func requirement() -> T<br>}<br>}<br><br>Presumably A<Int>.P and A<String>.P are distinct types, and A.P has a hidden associated type corresponding to the type parameter ’T’?<br><br>The other case is problematic too — the nested type might refer to an associated type of the outer protocol:<br><br>protocol P {<br>associatedtype A<br><br>struct T {<br>var value: A<br>}<br>}<br><br>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<C>.<br><br>Protocols nested inside protocols also have the same issue.<br></blockquote><br>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><br>Here’s a real life example pared down. I wish I could do this:<br><br>public struct ResponseContentTransformer<<wbr>InputContentType, OutputContentType>: ResponseTransformer {<br><br> public init(onInputTypeMismatch mismatchAction: InputTypeMismatchAction = .error) {<br> ...<br> }<br><br> public enum InputTypeMismatchAction { // Does not depend on generic types above<br> case error<br> case skip<br> case skipIfOutputTypeMatches<br> }<br><br>}<br><br>InputTypeMismatchAction is tightly associated with ResponseContentTransformer, and is confusing as a top-level type.<br><br>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><br>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><br>public struct S<T> {<br> public enum Foo {<br> case yin<br> case yang<br> }<br>}<br><br>…but this wouldn’t:<br><br>public struct S<T> {<br> public enum Foo {<br> case yin(thing: T) // capture of T illegal (for now)<br> case yang<br> }<br>}<br><br>Either of these approaches would allow hygienic namespacing now while leaving the door open to outer type capture in the future.<br></blockquote><br>Yeah, this makes sense for a first cut at this feature.<br><br>Slava<br></blockquote><br>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></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"><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">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"><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"><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">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"><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"><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"><br>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"><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"><br></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">Sorry, let this slip. Proposal sent - <a href="https://github.com/apple/swift-evolution/pull/552" target="_blank">https://github.com/apple/<wbr>swift-evolution/pull/552</a></div></div></blockquote><br></div></div></div><div>(Coming back to this after a very long time)</div><div><br></div><div>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., </div><div><br></div><div><font face="Menlo"><span class="m_-312512682317316134Apple-tab-span" style="white-space:pre-wrap">        </span>class UITableView {</font></div><div><font face="Menlo"><span class="m_-312512682317316134Apple-tab-span" style="white-space:pre-wrap">        </span> @objc(UITableViewDataSource)</font></div><div><font face="Menlo"><span class="m_-312512682317316134Apple-tab-span" style="white-space:pre-wrap">        </span> protocol DataSource { … }</font></div><div><font face="Menlo"><br></font></div><div><font face="Menlo"><span class="m_-312512682317316134Apple-tab-span" style="white-space:pre-wrap">        </span> @objc(UITableViewDelegate)</font></div><div><font face="Menlo"><span class="m_-312512682317316134Apple-tab-span" style="white-space:pre-wrap">        </span> protocol Delegate { … }</font></div><div><font face="Menlo"><span class="m_-312512682317316134Apple-tab-span" style="white-space:pre-wrap">        </span>}</font></div><div><br></div><div><span class="m_-312512682317316134Apple-tab-span" style="white-space:pre-wrap">        </span>- Doug</div><div><br></div><br></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>