<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=""><br class=""><div><blockquote type="cite" class=""><div class="">Am 29.04.2016 um 19:51 schrieb Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>>:</div><br class="Apple-interchange-newline"><div class="">Yes, certainly this works today. The motivation for Erica's question is that this would not work without modifying the third-party code if keywords were required to indicate implementation of protocol requirements.<br class=""></div></blockquote><div><br class=""></div></div><div>If I understood the motivation correctly, the requirements should protect against typos where I planned to *replace* a method but due to a typo instead created a new method and inherited the default (or superclass) implementation.</div><div><div>But this use case does not apply to modeling after the fact, because I simply *cannot make typos* there as the type to be extended in general is a third party type and cannot be edited by me.</div><div>Therefore extensions declaring conformance of a type to a protocol should not require any special markup for methods existing elsewhere (i.e. already in the type or other extensions of that type). </div><div>But requiring `override` markers for new methods written within the extension would still be sensible because these would again protect against typos in my own code.</div><div><br class=""></div><div>In addition some people like to split their types in parts writing them as extensions, e.g. one for each protocol conformance. This looks quite similar to modeling after the fact and the same rationale applies: requiring `override` markers within the extension make sense.</div><div><br class=""></div><div>So we would have:</div><div><br class=""></div><div>// third party code; using split declarations</div><div><br class=""></div><div>struct ThirdPartyProtocol {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>func bar()</div><div>}</div><div><br class=""></div><div>struct ThirdParty { </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>func foo() { … }</div><div>}</div><div><br class=""></div><div>extension ThirdParty : ThirdPartyProtocol {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>override func bar() { … } // `override` marker required</div><div>}</div><div><br class=""></div><div>// my code: modeling after the fact</div><div><br class=""></div><div>protocol A { </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>func foo() </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>func baz()</div><div>}</div><div><br class=""></div><div>extension ThirdParty : A {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>// no markers required for foo() </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>override func baz() { … } // `override` marker required</div><div>}</div><div><br class=""></div><div><br class=""></div><div><blockquote type="cite" class=""><div>One possible solution might emerge if it is possible to extend a protocol conditional on Self not being some concrete type. Thus, asking whether there is a way to express that.</div></blockquote><div class=""><div><br class=""></div></div><div>I do not see the need for that. This sounds like introducing something together with a workaround for it :-)</div><div>But maybe I have misunderstood what you intend.</div><div><br class=""></div></div><div>-Thorsten</div><div><br class=""></div><div><div class=""><br class=""></div></div><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_quote"><div dir="ltr" class="">On Fri, Apr 29, 2016 at 12:45 Thorsten Seitz <<a href="mailto:tseitz42@icloud.com" class="">tseitz42@icloud.com</a>> wrote:<br class=""></div><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="">No problem, that still works, because the most specific implementation is chosen:<div class=""><br class=""></div><div class=""><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(131,148,150)" class=""></div></div></div><div style="word-wrap:break-word" class=""><div class=""><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(131,148,150)" class=""><div style="margin:0px;line-height:normal" class=""><span style="color:#859901" class="">protocol</span><span class=""> A { </span><span style="color:#859901" class="">func</span><span class=""> foo()}</span></div><div style="margin:0px;line-height:normal;color:rgb(88,110,117)" class=""><span style="color:#859901" class="">protocol</span><span style="color:#839496" class=""> B {} </span><span class="">// empty protocol</span></div><div style="margin:0px;line-height:normal;min-height:15px" class=""><span class=""></span><br class=""></div></div></div></div><div style="word-wrap:break-word" class=""><div class=""><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(131,148,150)" class=""><div style="margin:0px;line-height:normal;color:rgb(133,153,1)" class=""><span class="">extension</span><span style="color:#839496" class=""> </span><span style="color:#b58901" class="">A</span><span style="color:#839496" class=""> {</span></div><div style="margin:0px;line-height:normal" class=""><span class=""> </span><span style="color:#859901" class="">func</span><span class=""> foo() {</span></div><div style="margin:0px;line-height:normal;color:rgb(41,161,152)" class=""><span style="color:#839496" class=""> </span><span style="color:#6c71c4" class="">print</span><span style="color:#839496" class="">(</span><span class="">"Self is A"</span><span style="color:#839496" class="">)</span></div></div></div></div><div style="word-wrap:break-word" class=""><div class=""><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(131,148,150)" class=""><div style="margin:0px;line-height:normal" class=""><span class=""> }</span></div><div style="margin:0px;line-height:normal" class=""><span class="">}</span></div><div style="margin:0px;line-height:normal;min-height:15px" class=""><span class=""></span><br class=""></div><div style="margin:0px;line-height:normal;color:rgb(133,153,1)" class=""><span class="">extension</span><span style="color:#839496" class=""> </span><span style="color:#b58901" class="">A</span><span style="color:#839496" class=""> </span><span class="">where</span><span style="color:#839496" class=""> </span><span class="">Self</span><span style="color:#839496" class="">: B {</span></div><div style="margin:0px;line-height:normal" class=""><span class=""> </span><span style="color:#859901" class="">func</span><span class=""> foo() {</span></div><div style="margin:0px;line-height:normal;color:rgb(41,161,152)" class=""><span style="color:#839496" class=""> </span><span style="color:#6c71c4" class="">print</span><span style="color:#839496" class="">(</span><span class="">"Self is B"</span><span style="color:#839496" class="">)</span></div><div style="margin:0px;line-height:normal" class=""><span class=""> }</span></div><div style="margin:0px;line-height:normal" class=""><span class="">}</span></div><div style="margin:0px;line-height:normal;min-height:15px" class=""><span class=""></span><br class=""></div><div style="margin:0px;line-height:normal;color:rgb(88,110,117)" class=""><span class="">// Works</span></div><div style="margin:0px;line-height:normal" class=""><span style="color:#859901" class="">struct</span><span class=""> S1: </span><span style="color:#b58901" class="">A</span><span class="">, </span><span style="color:#b58901" class="">B</span><span class=""> {}</span></div></div></div></div><div style="word-wrap:break-word" class=""><div class=""><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(131,148,150)" class=""><div style="margin:0px;line-height:normal;color:rgb(88,110,117)" class=""><span style="color:#b58901" class="">S1</span><span style="color:#839496" class="">().</span><span style="color:#6c71c4" class="">foo</span><span style="color:#839496" class="">() </span><span class="">// Self is B</span></div><div style="margin:0px;line-height:normal;min-height:15px" class=""><span class=""></span><br class=""></div><div style="margin:0px;line-height:normal" class=""><span style="color:#859901" class="">struct</span><span class=""> S2: </span><span style="color:#b58901" class="">A</span><span class=""> {}</span></div><div style="margin:0px;line-height:normal;color:rgb(88,110,117)" class=""><span style="color:#b58901" class="">S2</span><span style="color:#839496" class="">().</span><span style="color:#6c71c4" class="">foo</span><span style="color:#839496" class="">() </span><span class="">// Self is A</span></div><div style="margin:0px;line-height:normal;min-height:15px" class=""><span class=""></span><br class=""></div><div style="margin:0px;line-height:normal;min-height:15px" class=""><span class=""></span><br class=""></div><div style="margin:0px;line-height:normal;color:rgb(88,110,117)" class=""><span class="">// Wu's example works, too</span></div><div style="margin:0px;line-height:normal;min-height:15px" class=""><span class=""></span><br class=""></div><div style="margin:0px;line-height:normal" class=""><span style="color:#859901" class="">struct</span><span class=""> ThirdParty {</span></div><div style="margin:0px;line-height:normal" class=""><span class=""> </span><span style="color:#859901" class="">func</span><span class=""> foo() {</span></div><div style="margin:0px;line-height:normal;color:rgb(41,161,152)" class=""><span style="color:#839496" class=""> </span><span style="color:#6c71c4" class="">print</span><span style="color:#839496" class="">(</span><span class="">"Self is ThirdParty"</span><span style="color:#839496" class="">)</span></div><div style="margin:0px;line-height:normal" class=""><span class=""> }</span></div><div style="margin:0px;line-height:normal" class=""><span class="">}</span></div><div style="margin:0px;line-height:normal;min-height:15px" class=""><span class=""></span><br class=""></div><div style="margin:0px;line-height:normal;color:rgb(181,137,1)" class=""><span style="color:#859901" class="">extension</span><span style="color:#839496" class=""> </span><span class="">ThirdParty</span><span style="color:#839496" class=""> : </span><span class="">A</span><span style="color:#839496" class=""> {}</span></div><div style="margin:0px;line-height:normal;min-height:15px" class=""><span class=""></span><br class=""></div><div style="margin:0px;line-height:normal;color:rgb(88,110,117)" class=""><span style="color:#b58901" class="">ThirdParty</span><span style="color:#839496" class="">().</span><span style="color:#6c71c4" class="">foo</span><span style="color:#839496" class="">() </span><span class="">// Self is ThirdParty</span></div><div style="margin:0px;line-height:normal;min-height:15px" class=""><span class=""></span><br class=""></div><div style="margin:0px;line-height:normal;min-height:15px" class=""><span class=""></span><br class=""></div><div style="margin:0px;line-height:normal;color:rgb(88,110,117)" class=""><span class="">// dynamic dispatch works, too</span></div><div style="margin:0px;line-height:normal;min-height:15px" class=""><span class=""></span><br class=""></div><div style="margin:0px;line-height:normal" class=""><span style="color:#859901" class="">let</span><span class=""> a1: </span><span style="color:#b58901" class="">A</span><span class=""> = </span><span style="color:#b58901" class="">S1</span><span class="">()</span></div><div style="margin:0px;line-height:normal" class=""><span style="color:#d33682" class="">a1</span><span class="">.</span><span style="color:#6c71c4" class="">foo</span><span class="">()</span><span class=""> </span><span style="color:rgb(88,110,117)" class="">// Self is B</span></div><div style="margin:0px;line-height:normal;min-height:15px" class=""><span class=""></span><br class=""></div><div style="margin:0px;line-height:normal" class=""><span style="color:#859901" class="">let</span><span class=""> a2: </span><span style="color:#b58901" class="">A</span><span class=""> = </span><span style="color:#b58901" class="">S2</span><span class="">()</span></div><div style="margin:0px;line-height:normal" class=""><span style="color:#d33682" class="">a2</span><span class="">.</span><span style="color:#6c71c4" class="">foo</span><span class="">()</span><span class=""> </span><span style="color:rgb(88,110,117)" class="">// Self is A</span></div><div style="margin:0px;line-height:normal;min-height:15px" class=""><span class=""></span><br class=""></div><div style="margin:0px;line-height:normal;color:rgb(181,137,1)" class=""><span style="color:#859901" class="">let</span><span style="color:#839496" class=""> a3: </span><span class="">A</span><span style="color:#839496" class=""> = </span><span class="">ThirdParty</span><span style="color:#839496" class="">()</span><span style="color:rgb(131,148,150)" class=""> </span><span style="color:rgb(88,110,117)" class="">// Self is ThirdParty</span></div><div style="margin:0px;line-height:normal;color:rgb(108,113,196)" class=""><span style="color:#d33682" class="">a3</span><span style="color:#839496" class="">.</span><span class="">foo</span><span style="color:#839496" class="">()</span></div></div></div></div><div style="word-wrap:break-word" class=""><div class=""><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(88,110,117)" class=""><span class=""><br class=""></span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(88,110,117)" class=""><span class=""><br class=""></span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(88,110,117)" class=""><span style="font-family: Helvetica; font-size: 12px;" class="">-Thorsten</span></div></div></div><div style="word-wrap:break-word" class=""><div class=""><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(88,110,117)" class=""><span style="font-family: Helvetica; font-size: 12px;" class=""><br class=""></span></div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(88,110,117)" class=""><span style="font-family: Helvetica; font-size: 12px;" class=""><br class=""></span></div><div class=""><blockquote type="cite" class=""><div class="">Am 29.04.2016 um 17:20 schrieb Erica Sadun <<a href="mailto:erica@ericasadun.com" target="_blank" class="">erica@ericasadun.com</a>>:</div><br class=""><div class=""><div style="word-wrap:break-word" class=""><div class="">In Wux's example, he has third party code:</div><div class=""><br class=""></div><div class="">```</div><div class="">Type ThirdParty {</div><div class=""> func foo() { print("from third party") }</div><div class="">}</div><div class="">```</div><div class=""><br class=""></div><div class="">Then in his own code, he defines protocol A and extends it:</div><div class=""><br class=""></div><div class=""><div dir="auto" class=""><div class=""><div class=""><div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)" class=""><span class="">extension</span><span class=""> </span><span style="color:rgb(79,129,135)" class="">A</span><span class=""> {</span></div><div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo" class=""><span class=""> </span><span style="color:rgb(187,44,162)" class="">func</span><span class=""> foo() {</span></div><div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo;color:rgb(209,47,27)" class=""><span class=""> </span><span style="color:rgb(61,29,129)" class="">print</span><span class="">(</span><span class="">"Self is B"</span><span class="">)</span></div><div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo" class=""><span class=""> }</span></div><div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo" class=""><span class="">}</span></div></div></div></div><br class=""></div><div class="">and conforms ThirdParty to A. But he wants the original foo() implementation. Your approach</div><div class="">for writing an extension for plain A without a where clause doesn't offer that solution. The goal</div><div class="">here is "Add this default behavior *only* where a type does not conform to B"</div><div class=""><br class=""></div><div class="">-- E</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class="">On Apr 29, 2016, at 9:10 AM, Thorsten Seitz <<a href="mailto:tseitz42@icloud.com" target="_blank" class="">tseitz42@icloud.com</a>> wrote:</div><br class=""><div class=""><div dir="auto" class=""><div class=""></div><div class="">Just writing an extension for plain A without a where clause works.</div><div class=""><br class=""></div><div class="">-Thorsten </div><div class=""><br class="">Am 29.04.2016 um 16:03 schrieb Erica Sadun via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>>:<br class=""><br class=""></div><blockquote type="cite" class=""><div class="">Gmane is down as far as my browser is concerned and I haven't found anything by Googling.<div class=""><br class=""></div><div class="">Given the following:</div><div class=""><br class=""></div><div class=""><div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)" class=""><span class="">protocol</span><span class=""> A {</span><span class="">func</span><span class=""> foo()}</span></div><div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)" class=""><span style="color:#bb2ca2" class="">protocol</span><span class=""> B {} </span><span class="">// empty protocol</span></div><div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo;min-height:21px" class=""><span class=""></span><br class=""></div><div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)" class=""><span class="">extension</span><span class=""> </span><span style="color:#4f8187" class="">A</span><span class=""> </span><span class="">where</span><span class=""> </span><span class="">Self</span><span class="">:B {</span></div><div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo" class=""><span class=""> </span><span style="color:#bb2ca2" class="">func</span><span class=""> foo() {</span></div><div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo;color:rgb(209,47,27)" class=""><span class=""> </span><span style="color:#3d1d81" class="">print</span><span class="">(</span><span class="">"Self is B"</span><span class="">)</span></div><div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo" class=""><span class=""> }</span></div><div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo" class=""><span class="">}</span></div><div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo;min-height:21px" class=""><span class=""></span><br class=""></div><div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)" class=""><span class="">// Works</span></div><div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo" class=""><span style="color:#bb2ca2" class="">struct</span><span class=""> S1: </span><span style="color:#4f8187" class="">A</span><span class="">, </span><span style="color:#4f8187" class="">B</span><span class=""> {}</span></div><div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo" class=""><span style="color:#4f8187" class="">S1</span><span class="">().</span><span style="color:#31595d" class="">foo</span><span class="">()</span></div></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">Is there a way to produce a similar extension that exempts any type that conforms to B?</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">cc'ing in Wux because this is a direct response to a scenario he brought up yesterday.</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">-- E</span></div><div class=""><span class=""><br class=""></span></div></div></blockquote><blockquote type="cite" class=""><div class=""><span class="">_______________________________________________</span><br class=""><span class="">swift-evolution mailing list</span><br class=""><span class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a></span><br class=""><span class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br class=""></div></blockquote></div></div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></div></div></blockquote></div>
</div></blockquote></div><br class=""></body></html>