<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 Jun 6, 2016, at 12:22 AM, Dave Abrahams &lt;<a href="mailto:dabrahams@apple.com" class="">dabrahams@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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;" class="">on Sun Jun 05 2016, Matthew Johnson &lt;</span><a href="http://matthew-at-anandabits.com/" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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="">matthew-AT-anandabits.com</a><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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;" class="">&gt; wrote:</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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 style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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="">Sent from my iPhone<br class=""><br class=""><blockquote type="cite" class="">On Jun 5, 2016, at 3:51 PM, Dave Abrahams via swift-evolution<br class="">&lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class=""><br class=""><blockquote type="cite" class="">on Wed May 25 2016, Matthew Johnson &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class="">Sent from my iPad<br class=""><br class=""><blockquote type="cite" class="">On May 25, 2016, at 12:10 PM, Jordan Rose via swift-evolution<br class="">&lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class=""><br class=""><blockquote type="cite" class=""><blockquote type="cite" class="">On May 25, 2016, at 05:27, Brent Royal-Gordon via swift-evolution<br class="">&lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class="">AFAIK an existential type is a type T with type parameters that<br class="">are still abstract (see for example<br class=""><a href="https://en.wikipedia.org/wiki/Type_system#Existential_types" class="">https://en.wikipedia.org/wiki/Type_system#Existential_types</a>),<br class="">i.e. have not been assigned concrete values.<br class=""></blockquote><br class="">My understanding is that, in Swift, the instance used to store<br class="">something whose concrete type is unknown (i.e. is still abstract),<br class="">but which is known to conform to some protocol, is called an<br class="">"existential". Protocols with associated values cannot be packed<br class="">into normal existentials because, even though we know that the<br class="">concrete type conforms to some protocol, the associated types<br class="">represent additional unknowns, and Swift cannot be sure how to<br class="">translate uses of those unknown types into callable members. Hence,<br class="">protocols with associated types are sometimes called<br class="">"non-existential".<br class=""><br class="">If I am misusing the terminology in this area, please understand<br class="">that that's what I mean when I use that word.<br class=""></blockquote><br class="">We’re not consistent about it, but an “existential value” is a value<br class="">with protocol or protocol composition type. My mnemonic for this is<br class="">that all we know is that certain operations exist (unlike a generic<br class="">value, where we also have access to the type). John could explain it<br class="">more formally. We sometimes use “existentials” as a (noun) shorthand<br class="">for “existential value”.<br class=""><br class="">In the compiler source, all protocols and protocol compositions are<br class="">referred to as “existential types”, whether they have associated<br class="">types or not. Again, a protocol asserts the existence (and<br class="">semantics) of various operations, but nothing else about the<br class="">conforming type. (Except perhaps that it’s a class.) All protocols<br class="">are thus “existential types” whether or not the language supports<br class="">values having that type.<br class=""><br class="">It is incorrect to say that protocols with associated types (or<br class="">requirements involving Self) are “non-existential”.<br class=""></blockquote><br class="">I haven't heard people using this term myself, but I imagine they<br class="">probably mean "can't form an existential value with the protocol".<br class="">There certainly appears to be a lot of confusion in the community with<br class="">many not realizing that this is a temporary limitation of the<br class="">implementation, not a necessary fact.<br class=""></blockquote><br class="">As far as I know there is no known way to make protocols with Self<br class="">requirements usefully “existentiable,” or whatever you want to call it.<br class="">So unless I'm missing something, in this respect, the limitation is not<br class="">temporary at all.<br class=""></blockquote><br class="">Take a look at the Equatable example in the opening existentials<br class="">section of Doug's manifesto:<br class=""><a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160229/011666.html" class="">https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160229/011666.html</a><br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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;" class="">Yes, note that I said *usefully* “existential.” </span></div></blockquote><div><br class=""></div><div>Fair enough. &nbsp;But note that I was only talking about the inability to form and open such an existential which appears likely to be a temporary limitation given the generics manifesto (of course things could change).</div><br class=""><blockquote type="cite" class=""><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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;" class="">&nbsp;While we can of</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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;" class="">course downcast in this way, you have to handle the failure case and</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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;" class="">it's not like you can use this to make a heterogeneous Set&lt;Hashable&gt;.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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;" class="">AFAICT, this is not at all like what happens with associated types,</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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;" class="">where Collection&lt;Element: Int&gt; has obvious uses.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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></blockquote><div><br class=""></div><div>We can’t use this to form Set&lt;Hashable&gt; because existentials don’t conform to the protocol. &nbsp;I know there is complexity in implementing this and it is not possible to synthesize conformance of the existential for all protocols, but AFAIK it isn’t a settled point that we won’t try to improve the situation in some way. &nbsp;Maybe we can make progress here somehow. &nbsp;</div><div><br class=""></div><div>In the meantime, we can make a simple wrapper type to provide the required conformance and make a Set&lt;HashableWrapper&gt; that allows us to put Hashable into a Set. &nbsp;This isn’t ideal but it is a lot less boilerplate than is involved in manual type erasure today where you need to define a struct, base class, and wrapper class. &nbsp;I’d say that’s a win even if we’d like to do better in the future.</div><div><br class=""></div><div>struct HashableWrapper: Hashable {</div><div>&nbsp; &nbsp; var value: Hashable</div><div>&nbsp; &nbsp; public&nbsp;var&nbsp;hashValue:&nbsp;Int&nbsp;{ return base.hashValue }</div><div>}</div><div><br class=""></div><div>public&nbsp;func&nbsp;==(lhs:&nbsp;HashableWrapper, res:&nbsp;HashableWrapper) -&gt;&nbsp;Bool {</div><div><div class="">&nbsp; &nbsp; if let lhsValue = lhs.value&nbsp;openas T { &nbsp; &nbsp; // T is a the type of&nbsp;lhsValue, a copy of the value stored in lhs</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; if let rhsValue = rhs.value as? T { &nbsp; &nbsp; &nbsp;// is res also a T?</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // okay:&nbsp;lhsValue&nbsp;and&nbsp;rhsValue&nbsp;are both of type T, which we know is Equatable</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if&nbsp;lhsValue&nbsp;==&nbsp;rhsValue&nbsp;{&nbsp;</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return true</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;</div><div class="">&nbsp; &nbsp; }</div><div class="">&nbsp; &nbsp; return false</div></div><div>}</div><div><br class=""></div><div>(We could also do this with a generic Wrapper&lt;T&gt; and conditional conformance in an `extension Wrapper: Hashable where T == Hashable` if we don’t want a bunch of wrapper types laying around)</div><div><br class=""></div><div>-Matthew</div><br class=""><blockquote type="cite" class=""><div class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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;" class="">--<span class="Apple-converted-space">&nbsp;</span></span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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;" class="">-Dave</span></div></blockquote></div><br class=""></body></html>