<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">I would also love to have&nbsp;generic associated types&nbsp;in the language, I have a lot of uses for them and, IIUC, supertype constraint would enable me to express the following:<div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(30, 148, 33); background-color: rgb(255, 255, 255);" class=""><span style="color: #c42275" class="">protocol</span><span style="color: #000000" class=""> Service {}</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #c42275" class="">protocol</span> WikiService: <span style="color: #539aa4" class="">Service</span> {}&nbsp;<span style="color: rgb(30, 148, 33);" class="">// methods not shown for conciseness</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #c42275" class="">class</span> DefaultWikiService: <span style="color: #539aa4" class="">WikiService</span> {}</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #c42275" class="">class</span> DemoWikiService: <span style="color: #539aa4" class="">WikiService</span> {}</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #c42275" class="">class</span> DataServiceManager {</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; <span style="color: #c42275" class="">private</span> <span style="color: #c42275" class="">var</span> registry = [<span style="color: #703daa" class="">String</span>: <span style="color: #539aa4" class="">Service</span>]()</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; <span style="color: #c42275" class="">func</span> register&lt;S&gt;(<span style="color: #c42275" class="">_</span> service: <span style="color: #539aa4" class="">Service</span>, ofType type: <span style="color: #539aa4" class="">S</span>.Type) <span style="color: #c42275" class="">where</span> <span style="color: #539aa4" class="">S</span>: <span style="color: #539aa4" class="">Service</span> {</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c42275" class="">let</span> key = <span style="color: #c81b13" class="">"</span>\<span style="color: #c81b13" class="">(</span>Swift.type(of: type)<span style="color: #c81b13" class="">)"</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #539aa4" class="">registry</span>[key] = service</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; <span style="color: #c42275" class="">func</span> service&lt;S&gt;(ofType type: <span style="color: #539aa4" class="">S</span>.Type) -&gt; <span style="color: #539aa4" class="">S</span> <span style="color: #c42275" class="">where</span> <span style="color: #539aa4" class="">S</span>: <span style="color: #539aa4" class="">Service</span> {</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c42275" class="">let</span> key = <span style="color: #c81b13" class="">"</span>\<span style="color: #c81b13" class="">(</span>Swift.type(of: type)<span style="color: #c81b13" class="">)"</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(30, 148, 33); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span>// It is a programmer error to expect a value for a not yet registered type</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c42275" class="">guard</span> <span style="color: #c42275" class="">let</span> service = <span style="color: #539aa4" class="">registry</span>[key] <span style="color: #c42275" class="">as</span>? <span style="color: #539aa4" class="">S</span> <span style="color: #c42275" class="">else</span> {</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(200, 27, 19); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #3e1e81" class="">fatalError</span><span style="color: #000000" class="">(</span>"Service of type <span style="color: #000000" class="">\</span>(<span style="color: #000000" class="">type</span>) cannot be found. Please register a service for that type before accessing it."<span style="color: #000000" class="">)</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c42275" class="">return</span> service</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(60, 130, 139); background-color: rgb(255, 255, 255);" class=""><span style="color: #c42275" class="">let</span><span style="color: #000000" class=""> manager = </span>DataServiceManager<span style="color: #000000" class="">()</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(83, 154, 164); background-color: rgb(255, 255, 255);" class=""><span style="color: #c42275" class="">if</span><span style="color: #000000" class=""> </span>isDemoMode<span style="color: #000000" class=""> {</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(30, 148, 33); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class="">&nbsp; &nbsp; </span><span style="color: #539aa4" class="">manager</span><span style="color: #000000" class="">.register(</span><span style="color: #3c828b" class="">DemoWikiService</span><span style="color: #000000" class="">(), ofType: </span><span style="color: #539aa4" class="">WikiService</span><span style="color: #000000" class="">.</span><span style="color: #c42275" class="">self</span><span style="color: #000000" class="">) </span>// Currently: error: in argument type 'WikiService.Protocol', 'WikiService' does not conform to expected type 'Service'</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(196, 34, 117); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class="">} </span>else<span style="color: #000000" class=""> {</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(30, 148, 33); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class="">&nbsp; &nbsp; </span><span style="color: #539aa4" class="">manager</span><span style="color: #000000" class="">.register(</span><span style="color: #3c828b" class="">DefaultWikiService</span><span style="color: #000000" class="">(), ofType: </span><span style="color: #539aa4" class="">WikiService</span><span style="color: #000000" class="">.</span><span style="color: #c42275" class="">self</span><span style="color: #000000" class="">) </span>// Currently: error: in argument type 'WikiService.Protocol', 'WikiService' does not conform to expected type 'Service'</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div></div><div class=""><br class=""></div><div class="">If that's right, I'm also +1 on this :)</div><div class=""><br class=""></div><div class="">- Dennis</div><div class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Nov 25, 2017, at 12:13 AM, Adrian Zubarev 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 id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;" class="">In general this is more then welcome, so +1 for me.</div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;" class="">However I have one question:</div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;" class="">Could this allow support, or at least be a first step towards Swift allowing the following behaviour?</div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;" class="">```<br class=""><div id="bloop_customfont" style="margin: 0px;" class="">extension MyProtocol where Self : SomeClass {</div><div id="bloop_customfont" style="margin: 0px;" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>static func getSubtypes&lt;T&gt;(ofType _: T.Type = T.self) -&gt; [T] where T : Self { ... }</div><div id="bloop_customfont" style="margin: 0px;" class="">}</div>```</div><div style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><span style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">I would like to be able to upgrade `Self` to a class constraint, which then will allow me to only accept subtypes from T at compile time.</span><br style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div id="bloop_sign_1511565056096249088" class="bloop_sign" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"></div><br style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><p class="airmail_on" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Am 25. November 2017 um 00:03:23, Matthew Johnson via swift-evolution (<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>) schrieb:</p><blockquote type="cite" class="clean_bq" style="font-family: Helvetica, Arial; font-size: 13px; 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-size-adjust: auto; -webkit-text-stroke-width: 0px;"><span class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""></div><div class="">One of the most frequent frustrations I encounter when writing generic code in Swift is the requirement that supertype constraints be concrete. &nbsp;When I mentioned this on Twitter (<a href="https://twitter.com/anandabits/status/929958479598534656" class="">https://twitter.com/anandabits/status/929958479598534656</a>) Doug Gregor mentioned that this feature is smaller and mostly straightforward to design and implement (<a href="https://twitter.com/dgregor79/status/929975472779288576" class="">https://twitter.com/dgregor79/status/929975472779288576</a>).<div class=""><div class=""><br class=""></div><div class="">I currently have a PR open to add the high-level description of this feature found below to the generics manifesto (<a href="https://github.com/apple/swift/pull/13012" class="">https://github.com/apple/swift/pull/13012</a>):</div><div class=""><br class=""></div><div class=""><div class="">Currently, supertype constraints may only be specified using a concrete class or protocol type. &nbsp;This prevents us from abstracting over the supertype.</div><div class=""><br class=""></div><div class="">```swift</div><div class="">protocol P {</div><div class="">&nbsp; associatedtype Base</div><div class="">&nbsp; associatedtype Derived: Base</div><div class="">}</div><div class="">```</div><div class=""><br class=""></div><div class="">In the above example `Base` may be any type. &nbsp;`Derived` may be the same as `Base` or may be _any_ subtype of `Base`. &nbsp;All subtype relationships supported by Swift should be supported in this context including, but not limited to, classes and subclasses, existentials and conforming concrete types or refining existentials, `T?` and &nbsp;`T`, `((Base) -&gt; Void)` and `((Derived) -&gt; Void)`, etc.</div><div class=""><br class=""></div><div class="">Generalized supertype constraints would be accepted in all syntactic locations where generic constraints are accepted.</div></div><div class=""><br class=""></div><div class="">I would like to see generalized supertype constraints make it into Swift 5 if possible. &nbsp;I am not an implementer so I will not be able to bring a proposal forward alone but am interested in collaborating with anyone interested in working on implementation.</div><div class=""><br class=""></div><div class="">I am also interested in hearing general feedback on this feature from the community at large. &nbsp;Have you also found this limitation frustrating? &nbsp;In what contexts? &nbsp;Does anyone have reservations about introducing this capability? &nbsp;If so, what are they?<div class=""><br class=""></div><div class=""><div class="">Matthew</div><div class=""><div class=""><br class=""></div></div></div></div></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></div></span></blockquote><span style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:swift-evolution@swift.org" style="font-family: Helvetica, Arial; font-size: 13px; 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-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">swift-evolution@swift.org</a><br style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family: Helvetica, Arial; font-size: 13px; 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-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></div></div></body></html>