<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=""><div style="margin: 0px; line-height: normal;" class="">Shouldn’t we just narrow the type of protocols with associated types and/or Self types when the protocol is used as a type?</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(88, 110, 117);" class=""><br class=""></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(88, 110, 117);" class=""><div style="margin: 0px; line-height: normal;" class="">// (1) Associated types</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">protocol</span> Bounds {</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">func</span> doSomething()</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class="">}</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(133, 153, 1);" class="">protocol<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> Foo {</span></div><p style="margin: 0px; line-height: normal; color: rgb(131, 148, 150); min-height: 15px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">&nbsp; &nbsp; </span>// associated type with bounds</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">typealias</span> T <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">where</span> T: Bounds</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">&nbsp; &nbsp; </span>// getter is covariant, setter is contravariant</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">var</span> value: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">T</span> { <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">get</span> <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">set</span> }</div><p style="margin: 0px; line-height: normal; color: rgb(131, 148, 150); min-height: 15px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">&nbsp; &nbsp; </span>// result is covariant</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">func</span> foo() -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">T</span></div><p style="margin: 0px; line-height: normal; color: rgb(131, 148, 150); min-height: 15px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">&nbsp; &nbsp; </span>// arg is contravariant</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">func</span> bar(arg: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">T</span>)</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">func</span> baz(arg: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">T</span>) -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">T</span></div><p style="margin: 0px; line-height: normal; color: rgb(131, 148, 150); min-height: 15px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">&nbsp; &nbsp; </span>// arg of arg is covariant</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">func</span> f(g: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">T</span> -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Void</span>)</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class="">}</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">var</span> foo: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Foo</span></div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">// Covariant places of associated type T</div><div style="margin: 0px; line-height: normal;" class="">// are ok and use bounds of T&nbsp;</div><div style="margin: 0px; line-height: normal;" class="">// (i.e. Any if no bounds are given).</div><div style="margin: 0px; line-height: normal;" class="">// In our example the bounds are "Bounds"</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">let</span> x: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Bounds</span> = <span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">foo</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">value</span></div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">let</span> y: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Bounds</span> = <span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">foo</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #6c71c4" class="">foo</span>()</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">foo</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #6c71c4" class="">f</span> { (z: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Bounds</span>) <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">in</span> z.<span style="font-variant-ligatures: no-common-ligatures; color: #6c71c4" class="">doSomething</span>() }</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">// Contravariant places of associated type T</div><div style="margin: 0px; line-height: normal;" class="">// are forbidden, i.e. methods containing T</div><div style="margin: 0px; line-height: normal;" class="">// as argument or setters of variables of type T</div><div style="margin: 0px; line-height: normal;" class="">// are not allowed. In effect they are not part</div><div style="margin: 0px; line-height: normal;" class="">// of the type Foo.</div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">foo</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">value</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> = </span><span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">x</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> </span>// ERROR: calling setter not allowed</div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">foo</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #6c71c4" class="">bar</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">x</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">) </span>// ERROR: not allowed</div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">let</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> z: </span><span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Bounds</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> = </span><span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">foo</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #6c71c4" class="">baz</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">x</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">) </span>// ERROR: not allowed</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">// (2) Self types</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(133, 153, 1);" class="">protocol<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> Bar {</span></div><p style="margin: 0px; line-height: normal; color: rgb(131, 148, 150); min-height: 15px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">var</span> value: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Self</span> { <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">get</span> <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">set</span> }</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">func</span> foo() -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Self</span></div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">func</span> bar(arg: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Self</span>)</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">func</span> baz(arg: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Self</span>) -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Self</span></div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">func</span> f(g: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Self</span> -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Void</span>)</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class="">}</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">// Same as for associated types, just</div><div style="margin: 0px; line-height: normal;" class="">// that the bounds for Self are the protocol</div><div style="margin: 0px; line-height: normal;" class="">// itself, i.e. in this example: Bar</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">// (3) Constraining protocols with associated types or self types</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">protocol</span> Child : <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Bounds</span> {}</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">let</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> foo2: </span><span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Foo</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">where</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> T: Child </span>// would work like above with narrower bounds Child</div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">let</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> foo3: </span><span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Foo</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">where</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> T == Child </span>// would make all methods and setters available with T == Child</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">// (4) Equatable and Set</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">// Equatable with associated type EquatableWith like suggested by Joe Groff</div><div style="margin: 0px; line-height: normal; color: rgb(133, 153, 1);" class="">public<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> </span>protocol<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> Equatable {</span></div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">typealias</span> EquatesWith = Self&nbsp;<span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">where</span>&nbsp;Self: EquatesWith</div><div style="margin: 0px; line-height: normal; color: rgb(181, 137, 1);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">func</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> ==(lhs:&nbsp;</span><span style="color: rgb(131, 148, 150);" class="">EquatesWith</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">, rhs:&nbsp;</span><span style="color: rgb(131, 148, 150);" class="">EquatesWith</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">) -&gt; </span>Bool</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class="">}</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(133, 153, 1);" class="">protocol<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> P : </span><span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Hashable</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> {</span></div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">typealias</span>&nbsp;EquatesWith&nbsp;= P // fixing the associated type of Equatable</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">typealias</span> T <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">where</span> T: Bounds</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">func</span> foo() -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">T</span></div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">var</span> id: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Int</span></div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class="">}</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">func</span> ==(lhs: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">P</span>, rhs: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">P</span>) -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Bool</span> {</div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">return</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> lhs.</span><span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">id</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> == rhs.</span><span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">id</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> </span>// accessing id is ok</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class="">}</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">var</span> p1: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">P</span></div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">var</span> p2: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">P</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">if</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">p1</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #6c71c4" class="">==</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">p2</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> { </span>// ok, because EquatableWith has been fixed to be of type P</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #6c71c4" class="">print</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">"Ok!"</span>)</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class="">}</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">var</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> ps: </span><span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Set</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">&lt;</span><span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">P</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">&gt; </span>// now ok, because == can be used on variables of type p</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class=""><span style="color: rgb(211, 54, 130);" class="">ps</span>.insert(<span style="color: rgb(211, 54, 130);" class="">p1</span>)</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class=""><span style="color: rgb(211, 54, 130);" class="">ps</span>.insert(<span style="color: rgb(211, 54, 130);" class="">p2</span>)</div><div style="margin: 0px; line-height: normal; color: rgb(131, 148, 150);" class=""><span style="color: rgb(133, 153, 1);" class="">var</span>&nbsp;bs: [<span style="color: rgb(181, 137, 1);" class="">Bounds</span>] = <span style="color: rgb(211, 54, 130);" class="">ps</span>.map { $0.foo() } <span style="color: rgb(88, 110, 117);" class="">// ok</span></div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">With the proposed change of &nbsp;</div><div class="">-Thorsten</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">Am 14.12.2015 um 19:32 schrieb Joe Groff via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt;:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 14, 2015, at 7:40 AM, Dave Abrahams 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=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 14, 2015, at 6:23 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 style="font-family: AvenirNext-Regular; font-size: 14px; 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="">It is definitely possible to solve this problem for associated types by binding or constraining them. &nbsp;The ML module system has a feature that is roughly analogous to this. &nbsp;</div></div></blockquote><div class=""><br class=""></div>Keep in mind that a language feature like binding/constraining associated types is not a complete solution for real use-cases, so we would still need AnySequence&lt;Element&gt; in the library. &nbsp;Otherwise it would be SequenceType&lt;Generator: SomeGenerator&gt;, which binds a type that you don't actually want to expose.</div></div></div></blockquote></div><br class=""><div class="">With generic typealiases, you could say something like this:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class="">typealias AnySequence&lt;Element&gt; =</div><div class="">&nbsp; protocol&lt;SequenceType where Generator.Element == Element&gt;</div></blockquote><div class=""><br class=""></div><div class="">However, once we add 'where' requirements to protocols, it seems to me 'Element' really ought to be a direct requirement of SequenceType, like this:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class="">protocol SequenceType {</div><div class="">&nbsp; typealias Element</div><div class="">&nbsp; typealias Generator: GeneratorType</div><div class="">&nbsp; &nbsp; where Element == Generator.Element</div><div class="">}</div></blockquote><div class=""><br class=""></div><div class="">which would save generic code from having to splatter '.Generator.Element' everywhere, and make unspecialized code more efficient, since the type metadata for Element would be directly available from the SequenceType protocol witness table instead of needing an extra indirection through to its Generator's GeneratorType table.</div><div class=""><br class=""></div><div class="">-Joe</div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=1MXK54sosN3xru3iYcLt0oBZ2w20i49gyogXctgrspdCEAiA7IjqZmrcyPKq3YI-2FL29shR5-2BHg7MfuIBki8rzZUS3qKEwebwYLwsqwuJw-2Bc4NiyZ6nV5gur6RqmAWm55tSJu88yJfQxqNxprIXw43moEdKH7bv8ZUnHLXTF-2BLOTQR9qmOunkJRean2CMreXOv5ezVavd2vWYeXJU6JFmk-2BoVQu53RDqrjnrOb2YN6Ac-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
</div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>