I'm glad you brought this up and provided a clear example Xiaodi.

Erica, as I mentioned a few days ago (and Dave A gave +1) this proposal cannot 
break retroactive modeling if it is going to fly.  Can you please update it to 
clarify how you envision it interacts with retroactive modeling?  Would these 
new keywords only be required when the conformance is declared in the same 
module as the method? 

Sent from my iPad

> On Apr 28, 2016, at 12:48 PM, Xiaodi Wu via swift-evolution 
> <[email protected]> wrote:
> 
>> On Thu, Apr 28, 2016 at 12:25 PM, Erica Sadun <[email protected]> wrote:
>> >
>> > On Apr 28, 2016, at 11:05 AM, Xiaodi Wu <[email protected]> wrote:
>> >
>> > How is retroactive modeling accommodated in this scheme? Say I want to 
>> > conform three types I don't own to a protocol of my design and supply a 
>> > default implementation for a protocol requirement. How would I go about it?
>> 
>> extension NotMyType: ProtocolIdesigned {...}
>> 
>> extension NotMyProtocol {
>>      required func method1() {...}
>>      override required func method2() {...} // assumes NMP has already 
>> provided default
>>      func newThing() {...}
>> }
>> 
>> The only tricky bit is when NotMyProtocol already has a default required 
>> func implementation and an override required func implementation (although 
>> that should be rare). In such case, you probably have to create a new 
>> protocol DerivedProtocol: NotMyProtocol and work from there. The override in 
>> the DerivedProtocol will then take priority over the override in 
>> NotMyProtocol.
> 
> Sorry, that's not my question, which doesn't involve protocols I don't own. 
> Let me restate. Given three types I don't own as follows:
> 
> ```
> struct A {
>     func frobnicate() { print("A") }
> }
> struct B {
>     func frobnicate() { print("B") }
> }
> struct C { }
> ```
> 
> I want to conform them to a protocol of my own design, Frobnicatable, and 
> supply a default `frobnicate()`:
> 
> ```
> protocol Frobnicatable {
>     func frobnicate()
> }
> extension Frobnicatable {
>     func frobnicate() { print("Default") }
> }
> extension A: Frobnicatable { }
> extension B: Frobnicatable { }
> extension C: Frobnicatable { }
> 
> let c = C()
> c.frobnicate() // "Default"
> ```
> 
> (Yes, I realize there are issues regarding static and dynamic dispatch that 
> limit the utility of this particular example--let's leave those aside for 
> now.)
> Where would I affix keywords such as `required` and `override` to make this 
> work after implementation of your proposal?
> 
> _______________________________________________
> swift-evolution mailing list
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to