<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="">On Jan 4, 2016, at 9:54 AM, Matthew Johnson &lt;<a href="mailto:matthew@anandabits.com" class="">matthew@anandabits.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class=""><br class="Apple-interchange-newline">On Jan 4, 2016, at 11:43 AM, Douglas Gregor &lt;<a href="mailto:dgregor@apple.com" class="">dgregor@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-ligatures: normal; font-variant-position: normal; font-variant-caps: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class=""><br class="Apple-interchange-newline">On Jan 4, 2016, at 6:24 AM, Matthew Johnson via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On Jan 3, 2016, at 10:44 PM, Matthew Johnson &lt;<a href="mailto:matthew@anandabits.com" class="">matthew@anandabits.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 3, 2016, at 9:14 PM, Drew Crawford &lt;<a href="mailto:drew@sealedabstract.com" class="">drew@sealedabstract.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Sure, here's the start of the thread:&nbsp;<a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151207/001856.html" class="">https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151207/001856.html</a></div></div></blockquote><div class=""><br class=""></div>Thanks. &nbsp;Joe was basically saying is that associated types would be automatically bound to the existential for their constraints, or Any if there are no constraints. &nbsp;</div><div class=""><br class=""></div><div class="">He didn’t specifically mention anything about Self, but I suppose Self requirements could also be automatically bound to Any if the existential type doesn’t specify anything more specific, although I’m not sure I would like that behavior.</div><div class=""><br class=""></div><div class="">Self is what would apply in the case of:</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class="highlight highlight-source-swift" style="box-sizing: border-box; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);"><pre class="" style="box-sizing: border-box; overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal;"><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">compareTwo</span>(first: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Comparable</span>, _ <span class="pl-smi" style="box-sizing: border-box;">second</span>: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Comparable</span>) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-&gt;</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Int</span> {  <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// error!</span>
  <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">if</span> first <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">&lt;</span> second {
    <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">return</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">-1</span>
  }
  <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">//...</span>
}</pre></div></blockquote><div class="">If Self were automatically bound to Any what would this do? &nbsp;Would it compile and invoke a `&lt;` operator that takes two Any parameters? &nbsp;That doesn’t seem to make sense to me. &nbsp;It certainly wouldn’t guarantee you get the correct behavior if first and second were both Int for example.</div></div></div></div></blockquote><div class=""><br class=""></div><div class="">I gave this some further thought last night and realized what would happen here is pretty clear. &nbsp;I hadn’t considered existentials where associated types aren’t bound to concrete types before so it just took a few minutes to work through.</div><div class=""><br class=""></div><div class="">Existentials reference a witness table pointing to an actual implementations of the protocol requirements. &nbsp;Actual implementations require parameters of concrete types. &nbsp;This means that you must know what that concrete type is and supply a value of that type in order to actually call the member. &nbsp;The implication of this is that members which require parameters of an associated type that is not bound to a concrete type will not be available on that existential. &nbsp;</div></div></div></blockquote><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-ligatures: normal; font-variant-position: normal; font-variant-caps: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-ligatures: normal; font-variant-position: normal; font-variant-caps: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">There is a concrete type, which is known dynamically to the existential value, but you would need a way to name that type to (e.g.) cast down to it before you could use the member. That’s why the open..as operation I mentioned allows one to use these members: it gives a way to name the type. It actually helps to think of any operation on existentials as implicitly using open..as, because it makes the semantics far more explicit. (The compiler does this internally as well)</div></div></blockquote><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Casting down makes sense and of course you could use the member after that. &nbsp;But why do we need a special cast operation “open” to do this? &nbsp;Is there a reason we couldn’t just cast down with the usual operators like we can with `Any`?</div></div></blockquote><br class=""></div><div>How are you going to name the type you’re casting to?</div><div><br class=""></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>- Doug</div><div><br class=""></div><br class=""></body></html>