<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><br><br>Sent from my iPad</div><div><br>On May 29, 2016, at 10:22 PM, Charles Srstka &lt;<a href="mailto:cocoadev@charlessoft.com">cocoadev@charlessoft.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><blockquote type="cite" class="">On May 29, 2016, at 10:13 PM, Matthew Johnson &lt;<a href="mailto:matthew@anandabits.com" class="">matthew@anandabits.com</a>&gt; wrote:<br class=""></blockquote><div><blockquote type="cite" class=""><br class="Apple-interchange-newline"><div class=""><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="">On May 29, 2016, at 9:43 PM, Charles Srstka &lt;<a href="mailto:cocoadev@charlessoft.com" class="">cocoadev@charlessoft.com</a>&gt; wrote:<br class=""><br class=""></div><blockquote type="cite" 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=""><div class=""><blockquote type="cite" class="">On May 29, 2016, at 9:20 PM, Matthew Johnson &lt;<a href="mailto:matthew@anandabits.com" class="">matthew@anandabits.com</a>&gt; wrote:<br class=""></blockquote><div class=""><blockquote type="cite" class=""><br class="Apple-interchange-newline"><div class=""><div 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;">On May 29, 2016, at 5:43 PM, Charles Srstka via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class=""></div><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=""><blockquote type="cite" class="">On May 29, 2016, at 5:16 PM, Austin Zheng &lt;<a href="mailto:austinzheng@gmail.com" class="">austinzheng@gmail.com</a>&gt; wrote:<br class=""></blockquote><div class=""><blockquote type="cite" class=""><br class="Apple-interchange-newline"><div class=""><span 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; float: none; display: inline !important;">I think the problem here is that P == P is true, but P : P is not (a protocol does not conform to itself).</span><br 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></blockquote><div class=""><br class=""></div><div class="">But if you have a variable, parameter, etc. typed as P, that’s *not* the protocol, since protocols aren’t concrete entities. What you have there, by definition, is something that conforms to P. Similarly, something like [P] is just a collection of things, perhaps of various types, which all have the common feature that they conform to P.</div></div></div></blockquote><div 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;"><br class=""></div></div></blockquote><blockquote type="cite" class="">You have an existential value of type P. &nbsp;It is a well known frustration in Swift that the existential type corresponding to a protocol does not conform to the protocol. &nbsp;This has been discussed off and on at different times. &nbsp;<div class=""><br class=""></div><div class="">There are a couple of reasons this is the case. &nbsp;IIRC in some cases it actually isn't possible for the existential to conform to the protocol in a sound way. &nbsp;And even when it is possible, I believe it has been said that it is more difficult to implement than you might think. &nbsp;Hopefully the situation will improve in the future but I'm not aware of any specific plans at the moment.</div></blockquote></div><br class=""><div class="">It’s been my understanding that a variable typed P in swift is equivalent to what we would have called id &lt;P&gt; in Objective-C—that is, an object of unknown type that conforms to P. Is this not the case? I am curious what the conceptual difference would be, as well as the rationale behind it.</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="">Existentials have their own type in Swift. &nbsp;The problem you are running into is because the generic constraint is looking at the existential type of P and asking if that type conforms to P (which it does not - you can't write the conformance and the compiler does not provide it for you). &nbsp;It is not asking if the type of the object underlying the existential value conforms to P (which it necessarily does). &nbsp;When you have a value of type P you have already erased the type of the underlying object.</div></div></blockquote></div><br class=""><div class="">Have we not also erased the type of the underlying object with id &lt;P&gt;, though? The only thing we get from the “id” is that it’s an Objective-C object of some type, which it would have to have been anyway in order to conform to the protocol in the first place. Thus the type of the object is erased, and the only thing we know about it is that it conforms to the protocol—just like something typed P in Swift.</div></div></blockquote><div><br></div>In Swift values with the existential type P are not necessarily objects, they could be values. &nbsp;Because of this existentials are implemented a bit differently.<div><br><blockquote type="cite"><div><div class=""><br class=""></div><div class="">What I’m trying to figure out is whether there’s any positive benefit or rationale to the reason things work the way they do here, or whether it’s just bugs / implementation details.</div></div></blockquote><div><br></div><div>I think it's a bit of both. &nbsp;As I mentioned, IIRC there are cases where values of existential type *cannot* correctly conform to the protocol that they were derived from (I believe this is when Self or associated type requirements are involved). &nbsp;There are also cases where it is possible but is more difficult to implement than you might expect. &nbsp;I think we'll see progress eventually, but not in Swift 3.</div><br><blockquote type="cite"><div><div class=""><br class=""></div><div class="">Charles</div><div class=""><br class=""></div></div></blockquote></div></body></html>