[swift-evolution] [Discussion] Allowing extending existentials

Slava Pestov spestov at apple.com
Wed Feb 22 01:46:30 CST 2017


> On Feb 21, 2017, at 11:42 PM, David Hart via swift-evolution <swift-evolution at swift.org> wrote:
> 
> If we drop the idea of extending Any and AnyObject (which is out of scope), does the fact that what is left is syntactic sugar make it unsuitable for Swift 4? I remember Chris saying syntactic sugar is not the goal for Swift 4, but this syntactic sugar looks really sweet (pun intended).
> 

It’s unlikely we’ll make it a priority to implement anything like that in the Swift 4 timeframe, but PRs are more than welcome ;-)

Slava

> On 22 Feb 2017, at 08:36, Douglas Gregor <dgregor at apple.com <mailto:dgregor at apple.com>> wrote:
> 
>> 
>> 
>> Sent from my iPhone
>> 
>> On Feb 21, 2017, at 11:25 PM, David Hart via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>>> Yes, but it's not very discoverable. Plus, if the subclass existentials proposal is accepted, it would actually allow us to do:
>>> 
>>> class C {}
>>> extension C & P1 {}
>> 
>> ... which is 
>> 
>> extension P1 where Self: C1 {}
>> 
>> 
>> Actually extending semantics (e.g. to extend Any or AnyObject) is a very large project that's out of scope. Without that, this is a small bit of syntactic sugar. 
>> 
>>   - Doug
>> 
>>> 
>>> On 22 Feb 2017, at 08:06, Jacob Bandes-Storch <jtbandes at gmail.com <mailto:jtbandes at gmail.com>> wrote:
>>> 
>>>> This works today:
>>>> 
>>>> protocol P1{}
>>>> protocol P2{}
>>>> 
>>>> extension P1 where Self: P2 {
>>>>     func foo() {}
>>>> }
>>>> 
>>>> func bar(x: P1 & P2) {
>>>>     x.foo()
>>>> }
>>>> 
>>>> 
>>>> On Tue, Feb 21, 2017 at 10:53 PM, David Hart via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>>> Hello list,
>>>> 
>>>> Found out yesterday that you can’t extend all existentials in Swift:
>>>> 
>>>> protocol P1 {}
>>>> extension P1 {}
>>>> // works as expected
>>>> 
>>>> protocol P2 {}
>>>> extension P1 & P2 {}
>>>> // error: non-nominal type 'P1 & P2' cannot be extended
>>>> 
>>>> extension Any {}
>>>> // error: non-nominal type 'Any' cannot be extended
>>>> 
>>>> extension AnyObject {}
>>>> // error: 'AnyObject' protocol cannot be extended
>>>> 
>>>> I’d like to write a proposal to lift some of those restrictions. But the question is: which should be lifted? P1 & P2 seems like an obvious case. But what about Any and AnyObject? Is there a design reason that we shouldn’t allow it?
>>>> 
>>>> David.
>>>> 
>>>> _______________________________________________
>>>> swift-evolution mailing list
>>>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>>>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
>>>> 
>>>> 
>>> _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170221/fd6e8674/attachment.html>


More information about the swift-evolution mailing list