<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 Dec 13, 2015, at 11:03 PM, Paul Cantrell &lt;<a href="mailto:cantrell@pobox.com" class="">cantrell@pobox.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 13, 2015, at 11:56 PM, Dave Abrahams via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><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 Dec 13, 2015, at 3:55 PM, Marc Knaup via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div></blockquote></div></div></div></blockquote><blockquote type="cite" class="" style="font-family: HelveticaNeue;"><div class=""><div dir="ltr" class=""><div class=""><blockquote type="cite" class=""><blockquote type="cite" class="">Is there any info yet if and how we will be able to refer to instances of protocols that have associated types?</blockquote></blockquote></div></div></div></blockquote><blockquote type="cite" class=""><blockquote type="cite" class=""><br class=""></blockquote></blockquote><div style="font-family: HelveticaNeue;" class=""><blockquote type="cite" class=""><blockquote type="cite" class="">As far as I know, this isn't a solvable problem.</blockquote></blockquote></div></div><div class=""><blockquote type="cite" class=""><blockquote type="cite" class=""><br class=""></blockquote></blockquote></div><blockquote type="cite" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="">What is the difficulty in supporting this?</div></div></div></blockquote><br class=""></div><div class="">Here's a simple example:</div><div class=""><br class=""></div><div class="">protocol P {</div><div class="">&nbsp; typealias A</div><div class="">&nbsp; var x: A { get set }</div><div class="">}</div><div class=""><br class=""></div><div class="">struct Y : P {</div><div class="">&nbsp; var x: Int</div><div class="">}</div><div class=""><br class=""></div><div class="">struct Z : P {</div><div class="">&nbsp; var x: String</div><div class="">}</div><div class=""><br class=""></div><div class="">func f(p1: P, p2: P) {</div><div class="">&nbsp; p1.x = p2.x // assigning an Int to a String?</div><div class="">}</div></div></blockquote><br class=""></div><div class="">p1.x = p2.x should be a compiler error, because there’s not enough type information.</div></div></div></blockquote></div><div><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">But that shouldn’t stop a programmer from doing this:</div><div class=""><br class=""></div><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">protocol P {</div><div class="">&nbsp; typealias A</div><div class="">&nbsp; var x: A { get set }</div></div><div class="">&nbsp; var y: Int</div><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">}</div><div class=""><br class=""></div><div class="">struct Y : P {</div><div class="">&nbsp; var x: Int</div></div><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">&nbsp; var y: Int</div></div><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"></div></div><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">}</div><div class=""><br class=""></div><div class="">struct Z : P {</div><div class="">&nbsp; var x: String</div></div><div class="">&nbsp; var y: Int<br class=""></div><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">}</div><div class=""><br class=""></div></div><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">func maxY(p1: P, p2: P) -&gt; Int {</div><div class="">&nbsp; return max(p1.y, p2.y) &nbsp; // No problems here!</div><div class="">}</div></div><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><br class=""></div><div class="">…right?</div></div></div></div></div></div></blockquote><br class=""></div><div><div>Ah, but then you have the situation that P doesn't conform to P (it doesn't have an x that you can access). &nbsp;In my opinion that is just too weird an idea to be usable.</div><div>Personally, I have always thought that protocols intended to be used as unbound existentials (not P&lt;A: Int&gt;, just plain P) are different beasts entirely from the kind used as generic constraints and should be explicitly declared as such—I don't think I've ever seen a protocol that is well-used in both ways; if you have counterexamples I'd love to see them. &nbsp;In "existential protocols," declaring an associated type or creating a self requirement would be an error at the point of declaration. &nbsp;</div></div><br class=""><div class="">
-Dave<div class=""><br class=""></div><br class="Apple-interchange-newline">

</div>
<br class=""></body></html>