<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto">You’re right, I misunderstood that paragraph (maybe I read what I wanted to read :D). Thank you very much for the clarification and I’ll take a closer look at your proposal tomorrow!<br><br><div id="AppleMailSignature">- Dennis<br><div><br></div><div>Sent from my iPhone</div></div><div><br>On 25. Nov 2017, at 10:37 PM, Adrian Zubarev <<a href="mailto:adrian.zubarev@devandartist.com">adrian.zubarev@devandartist.com</a>> wrote:<br><br></div><blockquote type="cite"><div><style>body{font-family:Helvetica,Arial;font-size:13px}</style><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">Well no, this proposal won’t allow your example. The problem in your example actually has different roots - *Metatypes*. As by today, meta types are somehow broken, especially in generic / associated type context. Furthermore there is currently no way to express that you may want a subtype for an existential metatype instead of the static metatype.</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">For more informations about meta types and who some of us would like them to work, read our proposal here:</div><div id="bloop_customfont" style="margin: 0px;"><a href="https://github.com/DevAndArtist/swift-evolution/blob/refactor_existential_metatypes/proposals/0126-refactor-metatypes.md">https://github.com/DevAndArtist/swift-evolution/blob/refactor_existential_metatypes/proposals/0126-refactor-metatypes.md</a></div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;">Then your example could be expressed as:</div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;">```</div><div id="bloop_customfont" style="margin: 0px;">func register<S>(_ service: Service, ofType type: Type<S>) where AnyType<S> : AnyType<Service> {}</div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;">// or if I’m not mistaken we can make use if implicit existential like this then</div><div id="bloop_customfont" style="margin: 0px;">func register<S>(_ service: Service, ofType type: Type<S>) where S : Service {}</div><div id="bloop_customfont" style="margin: 0px;">```</div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;">I don't want to dive any deeper about the metatype pain points, because I don’t want to prevent the success of the pitched idea with an off-topic.</div> <br> <div id="bloop_sign_1511644328819648000" class="bloop_sign"></div> <br><p class="airmail_on">Am 25. November 2017 um 16:34:58, Dennis Weissmann (<a href="mailto:dennis@dennisweissmann.me">dennis@dennisweissmann.me</a>) schrieb:</p> <blockquote type="cite" class="clean_bq"><span><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div></div><div>
<title></title>
I would also love to have generic associated types 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>
{} <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=""> <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=""> <span style="color: #c42275" class="">func</span> register<S>(<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=""> <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=""> <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=""> }</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="">func</span> service<S>(ofType type: <span style="color: #539aa4" class="">S</span>.Type) -> <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=""> <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="">
</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=""> <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="">
</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=""> }</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="">return</span> service</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""> }</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> 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=""> </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=""> </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 <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> 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="">static
func getSubtypes<T>(ofType _: T.Type = T.self) -> [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;">
<div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">
<div class=""></div>
<div class=""><span class="">One of the most frequent frustrations
I encounter when writing generic code in Swift is the requirement
that supertype constraints be concrete. 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>).</span>
<div class="">
<div class=""><span class=""><br class=""></span></div>
<div class=""><span 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>):</span></div>
<div class=""><span class=""><br class=""></span></div>
<div class="">
<div class=""><span class="">Currently, supertype constraints may
only be specified using a concrete class or protocol type.
This prevents us from abstracting over the
supertype.</span></div>
<div class=""><span class=""><br class=""></span></div>
<div class=""><span class="">```swift</span></div>
<div class=""><span class="">protocol P {</span></div>
<div class=""><span class=""> associatedtype
Base</span></div>
<div class=""><span class=""> associatedtype Derived:
Base</span></div>
<div class=""><span class="">}</span></div>
<div class=""><span class="">```</span></div>
<div class=""><span class=""><br class=""></span></div>
<div class=""><span class="">In the above example `Base` may be any
type. `Derived` may be the same as `Base` or may be _any_
subtype of `Base`. 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 `T`,
`((Base) -> Void)` and `((Derived) -> Void)`,
etc.</span></div>
<div class=""><span class=""><br class=""></span></div>
<div class=""><span class="">Generalized supertype constraints
would be accepted in all syntactic locations where generic
constraints are accepted.</span></div>
</div>
<div class=""><span class=""><br class=""></span></div>
<div class=""><span class="">I would like to see generalized
supertype constraints make it into Swift 5 if possible. 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.</span></div>
<div class=""><span class=""><br class=""></span></div>
<div class=""><span class="">I am also interested in hearing
general feedback on this feature from the community at large.
Have you also found this limitation frustrating? In
what contexts? Does anyone have reservations about
introducing this capability? If so, what are they?</span>
<div class=""><span class=""><br class=""></span></div>
<div class="">
<div class=""><span class="">Matthew</span></div>
<div class="">
<div class=""><span class=""><br class=""></span></div>
</div>
</div>
</div>
</div>
<span class="">_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></span></div>
</div>
</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>
</div></div></span></blockquote></div></blockquote></body></html>