[swift-evolution] [Pre-pitch] Allowing enums inside protocols?
Karl Wagner
razielim at gmail.com
Tue Jul 11 18:00:05 CDT 2017
> On 9. Jul 2017, at 06:06, Xiaodi Wu via swift-evolution <swift-evolution at swift.org> wrote:
>
> On Sat, Jul 8, 2017 at 10:52 PM, Jonathan Hull <jhull at gbis.com <mailto:jhull at gbis.com>> wrote:
> Do you know why it was never brought to a vote?
>
> If I had to guess, it would be because the core team decided it's not in scope.
That’s pretty-much what happened. I wanted to allow nesting arbitrary types in protocols (e.g. FloatingPoint.Sign) and vice-versa (e.g. UITableView.Delegate). Wasn’t in scope.
>
> As an aside not central to your question and not directed to you specifically: There aren't votes in the evolution process; there are community and core team reviews. The purpose, afaik, isn't to count the number of replies that say "+1" or "-1."
>
> I seem to remember us having a pretty good consensus. I think we decided to punt on nested generics by just not allowing nesting in them yet (which would be compatible since that is what happens now too). Then we would have a second proposal to deal with generics/associated more carefully.
>
> I'm not aware of any proposal text that punts on nested generics.
Capturing generic type parameters between nested types works already. We lack the expressive ability to capture associated types between nested protocols (we would need generalised existentials). Capturing between generic types and associated types was controversial (and… yeah, that not exactly frictionless boundary between generic protocols and structural types is usually most people’s biggest problem with Swift’s generics).
Consider MyObject<T>.Delegate:
- Should we create a new protocol for every type T (allowing one object to conform to both MyObject<Int>.Delegate and MyObject<String>.Delegate)?, or
- Should there be one MyObject.Delegate protocol with an implicit associated-type “T”? e.g. "MyObject.Delegate where T == Int”. That would require "generalised existentials”.
So yeah, the proposal didn’t include capturing between nested protocols and types.
Also, I had some trouble nailing down the rules for when a nested type should be imported in to a conformer’s namespace. For example, you probably want Double.Sign to be an alias for FloatingPoint.Sign, but in general that might not always be true - especially if nested types and protocols can be added in extensions, things could get cluttered rather quickly. We don’t really have any formally-specified rules for unqualified lookup to take guidance from, either. In any case I think we should use the new protocol typealias lookup rules that appear to have popped up in Swift 3.2 - i.e. that typealiases inside the protocol body get inherited, but typealiases inside extensions don’t.
Long-term I really think we need to write down our rules for unqualified lookup. Something equivalent to this: http://en.cppreference.com/w/cpp/language/unqualified_lookup <http://en.cppreference.com/w/cpp/language/unqualified_lookup>
- Karl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170712/f0077494/attachment.html>
More information about the swift-evolution
mailing list