<div dir="ltr">+1 to &quot;opening&quot; values of existential type, I remember trying (and failing) to do this when Swift 1 came out. Being able to capture the dynamic type of an object at runtime and do stuff with it would be incredible.<div><br></div><div>Austin</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jan 3, 2016 at 4:19 PM, David Waite via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</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>This would be wonderful - is it something that could happen in the Swift 3 timeframe? Is it something that myself or someone else could work on a formal proposal for?</div><div><br></div><div>-DW</div><br><div><blockquote type="cite"><div><div class="h5"><div>On Jan 3, 2016, at 4:17 PM, Douglas Gregor via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br></div></div><div><div><div class="h5"><div dir="auto"><div><span></span></div><div><br><div style="direction:ltr"><blockquote type="cite"><div>On Jan 3, 2016, at 6:48 AM, Антон Жилин via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><div dir="ltr"><div style="font-size:12.8px">Introduction of interfaces will clean up the current blend of static and dynamic protocols, and solve at least three popular issues.</div><div style="font-size:12.8px">Please see:</div><div style="font-size:12.8px"><a href="https://github.com/Anton3/swift-evolution/blob/master/proposals/0000-introducing-interfaces.md" target="_blank">https://github.com/Anton3/swift-evolution/blob/master/proposals/0000-introducing-interfaces.md</a></div></div></div></blockquote><div style="direction:ltr"><br></div>I am *completely* against this proposal.</div><div style="direction:ltr"><br></div><div style="direction:ltr">Fundamentally, you&#39;re trying to address the limitation that protocols with Self or associated type requirements can&#39;t be existential. But it&#39;s just a limitation that isn&#39;t (conceptually) that hard to fix: the primary operation you need to work with an existing of such a protocol is to &quot;open&quot; a value of existential type, giving a name to the dynamic type it stores. Let&#39;s invent one:</div><div style="direction:ltr"><br></div><div style="direction:ltr">  func eq(x: Equatable, y: Equatable) -&gt; Bool {</div><div style="direction:ltr">    // give the name T to the dynamic type stored in xT</div><div style="direction:ltr">    let xT = open x as T</div><div style="direction:ltr">    // is y also storing a T?</div><div style="direction:ltr">    guard let yT = y as? T else { return false }</div><div style="direction:ltr">    // check whether the Ts are equal</div><div style="direction:ltr">    return xT == yT</div><div style="direction:ltr">  }</div><div style="direction:ltr"><br></div><div style="direction:ltr">Ignore the syntax: semantically, we&#39;ve gone from a &quot;dynamic&quot; existential thing back to something more &quot;static&quot;, just by giving a name to the type. Swift generics aren&#39;t really even static in any sense: what the do is give names to the types of values so one can establish relationships among different values. &quot;open..as&quot; would do that for existentials. </div><div style="direction:ltr"><br></div><div style="direction:ltr">Note that ether Swift compilers AST and SIL both have &quot;open existential&quot; operations that do this internally. They have no spelling in Swift code, but they are useful to describe operations on existentials. At present, they cannot be formed when the existential involves a protocol with Self or associated type requirements, but that&#39;s a limitation that isn&#39;t hard to address. </div><div style="direction:ltr"><br></div><div style="direction:ltr">As for your concerns about knowing when one can dynamically override and when one cannot...  There are issues here that need to be addressed. They aren&#39;t significant enough to warrant such a drastic change, and may not even require language changes at all. </div><div style="direction:ltr"><br></div><div style="direction:ltr"><span style="white-space:pre-wrap">        </span>- Doug</div><div style="direction:ltr"><br></div><div style="direction:ltr"><br></div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=nE9rxSXA5G4kxsTVkgv43vFcOQoCM-2FU-2BigXPSqPoICLQMF0Is2N1gVcYyd8LXauWU01V8ADskXgeA1dZAXS87kb5mrtSnua8ix3PvTqk8IjbkCFnioGdyq-2BKvhwvXwvyetVprM5QJNhgoafyPtUnsoK0Jd9PVrhUVERURHcV29O9ap7P5ZtW-2FOxTbxXomN8xjYwI10z8Hb2x7y5-2BqncZc5sWcNEbG-2B6FFuGHrYPzWeE-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
</div></div></div><span class="">
_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></span></div></blockquote></div><br>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=7XtDdMHRjqIUi4tzSjSp2pWQIyxYdP6woIWn4vwV5gcqFr4r03Dh8eKogFpiDvey1PIPaqe7zBTWkGgzjr7woVXbaxXCaffQPyqbNaWrCT31DHMqDKbDyZXdXLG0uJnEExUVUN9oEhXVqTbecWfsT7Rc3IiNpSEkALkUkC9ps1q0uigaGtwHxjKWfy7jae9C3Wddeg44wsab4HqrarOmVSVje8zK97AHm-2FldU6Lkrf0-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
</div>
<br>_______________________________________________<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/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>