<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 <<a href="mailto:cantrell@pobox.com" class="">cantrell@pobox.com</a>> 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 <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> 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 <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> 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=""> typealias A</div><div class=""> var x: A { get set }</div><div class="">}</div><div class=""><br class=""></div><div class="">struct Y : P {</div><div class=""> var x: Int</div><div class="">}</div><div class=""><br class=""></div><div class="">struct Z : P {</div><div class=""> var x: String</div><div class="">}</div><div class=""><br class=""></div><div class="">func f(p1: P, p2: P) {</div><div class=""> 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=""> typealias A</div><div class=""> var x: A { get set }</div></div><div class=""> 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=""> var x: Int</div></div><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""> 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=""> var x: String</div></div><div class=""> 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) -> Int {</div><div class=""> return max(p1.y, p2.y) // 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). 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<A: Int>, 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. In "existential protocols," declaring an associated type or creating a self requirement would be an error at the point of declaration. </div></div><br class=""><div class="">
-Dave<div class=""><br class=""></div><br class="Apple-interchange-newline">
</div>
<br class=""></body></html>