<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>Thanks for these explanations. &nbsp;It sounds like you guys want to build this feature so it's just a matter of waiting until it has the priority. &nbsp;&nbsp;</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">Until then, every box that gets checked on the generics manifesto is much appreciated.</div><div id="AppleMailSignature"><br>-Matt</div><div><br>On Jan 30, 2017, at 15:17, Douglas Gregor &lt;<a href="mailto:dgregor@apple.com">dgregor@apple.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 29, 2017, at 8:35 PM, Slava Pestov 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: 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=""><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On Jan 29, 2017, at 1:03 PM, Matt Whiteside 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 class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">In Swift 3.1, I was happy to see that we can now extend types with concrete constraints. &nbsp;I think one other feature which fits nicely with this new capability would be extending typealiases, like this:</div><div class=""><br class=""></div><div class=""><b class=""><font face="FiraMono-Regular" class="">typealias Vector = Array&lt;Float&gt;</font></b></div><div class=""><b class=""><font face="FiraMono-Regular" class=""><br class=""></font></b></div><div class=""><b class=""><font face="FiraMono-Regular" class="">extension Vector {</font></b><b class=""><font face="FiraMono-Regular" class="">&nbsp;</font></b></div><div class=""><b class=""><font face="FiraMono-Regular" class="">&nbsp; &nbsp;...</font></b></div><div class=""><b class=""><font face="FiraMono-Regular" class="">}</font></b></div><div class=""><b class=""><br class=""></b></div><div class="">Which currently doesn't compile due to: &nbsp;"Constrained extension must be declared on the unspecialized generic type 'Array' with constraints specified by a 'where’ clause”</div><div class=""><br class=""></div><div class="">What is other people’s interest level? &nbsp;How possible would it be to add this?</div></div></div></blockquote><div class=""><br class=""></div>I think this particular case would be pretty easy to add, but there is a more general case with generic typealiases that requires some thought:</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=""><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="">typealias OptionalArray&lt;T&gt; = Optional&lt;Array&lt;T&gt;&gt;</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=""><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="">extension OptionalArray {</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="">&nbsp; …</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="">}</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=""><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="">Without generic typealiases, you might imagine this could be written as something like</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=""><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="">extension &lt;T&gt; Optional&lt;Array&lt;T&gt;&gt; {</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="">&nbsp; …</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="">}</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=""><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="">I think this is called out in the generics manifesto as a potential future feature. I’m not sure how much work it would take to add it but I imagine it’s not entirely trivial.</div></div></blockquote><br class=""></div><div>The implementation here would probably not be trivial. There are two general issues, the first of which also applies to extending typealiases:</div><div><br class=""></div><div>1) The type checker doesn’t have a principled way of resolving the name of the extended type, so to correctly look through typealiases would require a bunch of reworking of the way we do lookup there. This would be a fantastic improvement to the compiler and would fix a bunch of bugs with extending nested types, too :)</div><div><br class=""></div><div>2) There are undoubtedly a number of places in the compiler where we assume that the generic parameters of an extension are the same as the generic parameters of the nominal type, but this will no longer be true if we allow extension of generic typealiases. For example:</div><div><br class=""></div><div>struct Pair&lt;T, U&gt; { }</div><div><br class=""></div><div>typealias Array2&lt;V&gt; = Pair&lt;V, V&gt;</div><div><br class=""></div><div>extension Array2 { // extension has one generic parameter, but Pair has two generic parameters</div><div>}</div><div><br class=""></div><div>It’s likely not *hard* to fix these issues, but it’ll be a game of whack-a-mole throughout the compiler.</div><div><br class=""></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>- Doug</div><div><br class=""></div><br class=""></div></blockquote></body></html>