<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 Apr 24, 2017, at 2:33 PM, Joshua Alvarado &lt;<a href="mailto:alvaradojoshua0@gmail.com" class="">alvaradojoshua0@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="content-type" content="text/html; charset=utf-8" class=""><div dir="auto" class=""><div class="">Hmmm interesting point it would be good to consider this and get to an implementation that helps cover both or just implement the desired feature and in the future add more resiliency.&nbsp;<br class=""><br class="">Alvarado, Joshua</div><div class=""><br class="">On Apr 24, 2017, at 2:41 PM, Jaden Geller &lt;<a href="mailto:jaden.geller@gmail.com" class="">jaden.geller@gmail.com</a>&gt; wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Apr 24, 2017, at 1:34 PM, Joshua Alvarado 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 dir="ltr" class=""><div class="">Well in your case thing one and thing two will be the same type as you are using the same T generic type on both.</div><div class=""><br class=""></div><div class="">To achieve your case you can do an extension on the enum and use two different generics:</div><div class=""><br class=""></div><div class=""><div style="font-family:menlo;font-size:11px;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">enum</span><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp;Thing {</span></div><div style="font-family:menlo;font-size:11px;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">case</span><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp;thingOne&lt;T&gt;(T)</span></div><div style="font-family:menlo;font-size:11px;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">case</span><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp;thingTwo&lt;U&gt;(U)</span></div><div style="font-family:menlo;font-size:11px;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">}</span></div><div style="font-family:menlo;font-size:11px;margin:0px;line-height:normal;min-height:13px" class=""><br class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span></div><div style="font-family:menlo;font-size:11px;margin:0px;line-height:normal;min-height:13px" class="">extension Thing where T == String, U == Int {</div><div style="font-family:menlo;font-size:11px;margin:0px;line-height:normal;min-height:13px" class="">&nbsp; &nbsp;<span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">func</span><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp;handle(thing:&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Thing</span><span style="font-variant-ligatures:no-common-ligatures" class="">) {</span></div><div style="font-family:menlo;font-size:11px;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">switch</span><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp;thing {</span></div><div style="font-family:menlo;font-size:11px;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">case</span><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp;thingOne(let s):</span></div><div style="font-family:menlo;font-size:11px;margin:0px;line-height:normal;color:rgb(0,132,0)" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures" class="">// s is type String</span></div><div style="font-family:menlo;font-size:11px;margin:0px;line-height:normal;color:rgb(0,132,0)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span></div><div style="font-family:menlo;font-size:11px;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">case</span><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp;thingTwo</span><span style="font-variant-ligatures:no-common-ligatures" class="">(let i):</span></div><div style="font-family:menlo;font-size:11px;margin:0px;line-height:normal;color:rgb(0,132,0)" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures" class="">// i is an Int</span></div><div style="font-family:menlo;font-size:11px;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="font-family:menlo;font-size:11px;margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp;}</span></div><div style="font-family:menlo;font-size:11px;margin:0px;line-height:normal;min-height:13px" class="">}</div></div></div></div></blockquote></div></div></blockquote></div></div></blockquote><div><br class=""></div><div>I think it’s important to not that the above example (without generic information carried with the type) should not be able to provide an extension that constrains the type. The problem is that, since we don’t know what `T` and `U` actually are for an arbitrary instance at compile-time, we cannot ensure that `handle` is not called when `T` and `U` don’t match the extension. We’d have to require an implementation of `handle` for every possible type. I guess it _could_ be reasonable to allow such a constrained extension if we already defined `handle` for any `T` and `U`, but this implementation would probably be simple (and equivalent after optimization):</div><div><br class=""></div><div>```</div><div><div style="margin: 0px 0px 0px 31.5px; text-indent: -31.6px; line-height: normal; font-family: Monaco; font-size: 11px;" class=""><span style="color: #c900a4" class="">enum</span> Thing {</div><div style="margin: 0px 0px 0px 63px; text-indent: -63.1px; line-height: normal; font-family: Monaco; font-size: 11px;" class="">&nbsp; &nbsp; <span style="color: #c800a4" class="">case</span> thingOne<span style="color: #c800a4" class="">&lt;</span>T<span style="color: #c800a4" class="">&gt;</span>(T)</div><div style="margin: 0px 0px 0px 63px; text-indent: -63.1px; line-height: normal; font-family: Monaco; font-size: 11px;" class="">&nbsp; &nbsp; <span style="color: #c800a4" class="">case</span> thingTwo<span style="color: #c800a4" class="">&lt;</span>U<span style="color: #c800a4" class="">&gt;</span>(U)</div><p style="margin: 0px 0px 0px 63px; text-indent: -63.1px; line-height: normal; font-family: Monaco; min-height: 17px; font-size: 11px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px 0px 0px 63px; text-indent: -63.1px; line-height: normal; font-family: Monaco; font-size: 11px;" class="">&nbsp; &nbsp; <span style="color: #c900a4" class="">func</span> handle() {</div><div style="margin: 0px 0px 0px 94.6px; text-indent: -94.7px; line-height: normal; font-family: Monaco; font-size: 11px;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c800a4" class="">switch</span> <span style="color: #c800a4" class="">self</span> {</div><div style="margin: 0px 0px 0px 94.6px; text-indent: -94.7px; line-height: normal; font-family: Monaco; font-size: 11px;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c800a4" class="">case</span> <span style="color: #c800a4" class="">.</span>thingOne<span style="color: #c800a4" class="">&lt;</span>T<span style="color: #c800a4" class="">&gt;</span>(<span style="color: #c900a4" class="">let</span> s):</div><div style="margin: 0px 0px 0px 126.1px; text-indent: -126.2px; line-height: normal; font-family: Monaco; font-size: 11px;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c800a4" class="">if</span> T <span style="color: #c800a4" class="">is</span> <span style="color: #790ead" class="">String</span> {</div><div style="margin: 0px 0px 0px 157.7px; text-indent: -157.7px; line-height: normal; font-family: Monaco; color: rgb(0, 142, 0); font-size: 11px;" class=""><span style="color: #000000" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>// s is of type String</div><div style="margin: 0px 0px 0px 126.1px; text-indent: -126.2px; line-height: normal; font-family: Monaco; font-size: 11px;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } <span style="color: #c800a4" class="">else</span> {</div><div style="margin: 0px 0px 0px 157.7px; text-indent: -157.7px; line-height: normal; font-family: Monaco; color: rgb(0, 142, 0); font-size: 11px;" class=""><span style="color: #000000" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>// default case!</div><div style="margin: 0px 0px 0px 126.1px; text-indent: -126.2px; line-height: normal; font-family: Monaco; font-size: 11px;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px 0px 0px 94.6px; text-indent: -94.7px; line-height: normal; font-family: Monaco; font-size: 11px;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c800a4" class="">case</span> <span style="color: #c800a4" class="">.</span>thingTwo<span style="color: #c800a4" class="">&lt;</span>U<span style="color: #c800a4" class="">&gt;</span>(<span style="color: #c900a4" class="">let</span> i):</div><div style="margin: 0px 0px 0px 126.1px; text-indent: -126.2px; line-height: normal; font-family: Monaco; font-size: 11px;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c800a4" class="">if</span> U <span style="color: #c800a4" class="">is</span> <span style="color: #790ead" class="">Int</span> {</div><div style="margin: 0px 0px 0px 157.7px; text-indent: -157.7px; line-height: normal; font-family: Monaco; font-size: 11px;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008e00" class="">// i is an Int</span></div><div style="margin: 0px 0px 0px 126.1px; text-indent: -126.2px; line-height: normal; font-family: Monaco; font-size: 11px;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } <span style="color: #c800a4" class="">else</span> {</div><div style="margin: 0px 0px 0px 157.7px; text-indent: -157.7px; line-height: normal; font-family: Monaco; color: rgb(0, 142, 0); font-size: 11px;" class=""><span style="color: #000000" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>// default case!</div><div style="margin: 0px 0px 0px 126.1px; text-indent: -126.2px; line-height: normal; font-family: Monaco; font-size: 11px;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px 0px 0px 94.6px; text-indent: -94.7px; line-height: normal; font-family: Monaco; font-size: 11px;" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px 0px 0px 63px; text-indent: -63.1px; line-height: normal; font-family: Monaco; font-size: 11px;" class="">&nbsp; &nbsp; }</div><div style="margin: 0px 0px 0px 31.5px; text-indent: -31.6px; line-height: normal; font-family: Monaco; font-size: 11px;" class="">}</div></div><div>```</div><div><br class=""></div><div>Cheers,</div><div>Jaden Geller</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="auto" class=""><blockquote type="cite" class=""><div class=""><div class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div style="font-family:menlo;font-size:11px;margin:0px;line-height:normal;min-height:13px" class=""><br class=""></div><div style="font-family:menlo;font-size:11px;margin:0px;line-height:normal;min-height:13px" class="">This can actually be achieved in Swift 3.1, you can run this in a playground.</div></div></div></div></blockquote><div class=""><br class=""></div><div class="">This is not quite the same. In the original example, the type information was thrown away after an instance of type `Foo` was constructed.</div><div class=""><br class=""></div><div class="">Here’s an example that wouldn’t work in your model:</div><div class=""><br class=""></div><div class="">```</div><div class=""><div dir="ltr" class=""><div class=""><div class="" style="font-family: menlo; font-size: 11px; margin: 0px; line-height: normal; min-height: 13px;"><div class="" style="margin: 0px; line-height: normal;"><div dir="ltr" class=""><div class=""><div class="" style="font-family: menlo; font-size: 11px; margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">enum</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;Whatever {</span></div><div class="" style="font-family: menlo; font-size: 11px; margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp;&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">case</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;some&lt;T&gt;(T)</span></div><div class="" style="font-family: menlo; font-size: 11px; margin: 0px; line-height: normal;">}</div><div class="" style="font-family: menlo; font-size: 11px; margin: 0px; line-height: normal;"><br class=""></div><div class="" style="font-family: menlo; font-size: 11px; margin: 0px; line-height: normal;"><font color="#ba2da2" class="">var&nbsp;</font>x: Whatever = .some(3)</div><div class="" style="font-family: menlo; font-size: 11px; margin: 0px; line-height: normal;">x = .some([1, 2, 3])</div><div class="" style="font-family: menlo; font-size: 11px; margin: 0px; line-height: normal;"><div style="font-family: Helvetica; font-size: 12px;" class="">```</div><div style="font-family: Helvetica; font-size: 12px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px;" class="">If `Whatever` was generic in `T`, then a variable can only store case payloads with that specific type. I guess this could be worked around by introducing a `AnyWhatever` protocol, but still, it’s not an identical feature.</div><div style="font-family: Helvetica; font-size: 12px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px;" class="">That said, it might be true that this isn’t actually a desirable feature. We ought to definitely consider the implications of it and any alternatives. Thanks for mentioning this, it’s a decent workaround dependent on what you’d like to accomplish!</div><div style="font-family: Helvetica; font-size: 12px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px;" class="">Cheers,</div><div style="font-family: Helvetica; font-size: 12px;" class="">Jaden Geller</div></div><div class="" style="font-family: menlo; font-size: 11px; margin: 0px; line-height: normal;"><br class=""></div></div></div></div></div></div></div></div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div style="font-family:menlo;font-size:11px;margin:0px;line-height:normal;min-height:13px" class=""><br class=""></div><div style="font-family:menlo;font-size:11px;margin:0px;line-height:normal;min-height:13px" class=""><div style="margin: 0px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(54,86,138)" class="">enum</span><span style="font-variant-ligatures:no-common-ligatures" class=""> Foo&lt;T, U&gt; {</span></div><div style="margin: 0px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(54,86,138)" class="">case</span><span style="font-variant-ligatures:no-common-ligatures" class=""> bar(obj: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(195,89,0)" class="">T</span><span style="font-variant-ligatures:no-common-ligatures" class="">)</span></div><div style="margin: 0px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(54,86,138)" class="">case</span><span style="font-variant-ligatures:no-common-ligatures" class=""> baz(obj: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(195,89,0)" class="">U</span><span style="font-variant-ligatures:no-common-ligatures" class="">)</span></div><div style="margin: 0px; line-height: normal; font-family: menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(54,86,138)" class="">func</span><span style="font-variant-ligatures:no-common-ligatures" class=""> handle() {</span></div><div style="margin: 0px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(54,86,138)" class="">switch</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(54,86,138)" class="">self</span><span style="font-variant-ligatures:no-common-ligatures" class=""> {</span></div><div style="margin: 0px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(54,86,138)" class="">case</span><span style="font-variant-ligatures:no-common-ligatures" class=""> .</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(88,126,168)" class="">bar</span><span style="font-variant-ligatures:no-common-ligatures" class="">(obj: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(54,86,138)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> x):</span></div><div style="margin: 0px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(54,86,138)" class="">break</span></div><div style="margin: 0px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(54,86,138)" class="">case</span><span style="font-variant-ligatures:no-common-ligatures" class=""> .</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(88,126,168)" class="">baz</span><span style="font-variant-ligatures:no-common-ligatures" class="">(obj: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(54,86,138)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> y):</span></div><div style="margin: 0px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(54,86,138)" class="">break</span></div><div style="margin: 0px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin: 0px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">}</span></div><div style="margin: 0px; line-height: normal; font-family: menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(54,86,138)" class="">extension</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(195,89,0)" class="">Foo</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(54,86,138)" class="">where</span><span style="font-variant-ligatures:no-common-ligatures" class=""> T == String, U == Int {</span></div><div style="margin: 0px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(54,86,138)" class="">func</span><span style="font-variant-ligatures:no-common-ligatures" class=""> handle() {</span></div><div style="margin: 0px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(54,86,138)" class="">switch</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(54,86,138)" class="">self</span><span style="font-variant-ligatures:no-common-ligatures" class=""> {</span></div><div style="margin: 0px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(54,86,138)" class="">case</span><span style="font-variant-ligatures:no-common-ligatures" class=""> .</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(88,126,168)" class="">bar</span><span style="font-variant-ligatures:no-common-ligatures" class="">(obj: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(54,86,138)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> str):</span></div><div style="margin: 0px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(88,126,168)" class="">print</span><span style="font-variant-ligatures:no-common-ligatures" class="">(str)</span></div><div style="margin: 0px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(54,86,138)" class="">case</span><span style="font-variant-ligatures:no-common-ligatures" class=""> .</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(88,126,168)" class="">baz</span><span style="font-variant-ligatures:no-common-ligatures" class="">(obj: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(54,86,138)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> aNum):</span></div><div style="margin: 0px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(88,126,168)" class="">print</span><span style="font-variant-ligatures:no-common-ligatures" class="">(aNum)</span></div><div style="margin: 0px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin: 0px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">}</span></div><div style="margin: 0px; line-height: normal; font-family: menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(54,86,138)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> foo = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(195,89,0)" class="">Foo</span><span style="font-variant-ligatures:no-common-ligatures" class="">&lt;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(195,89,0)" class="">String</span><span style="font-variant-ligatures:no-common-ligatures" class="">, </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(195,89,0)" class="">Int</span><span style="font-variant-ligatures:no-common-ligatures" class="">&gt;.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(88,126,168)" class="">baz</span><span style="font-variant-ligatures:no-common-ligatures" class="">(obj: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(54,86,138)" class="">1</span><span style="font-variant-ligatures:no-common-ligatures" class="">)</span></div><p style="margin: 0px; line-height: normal;" class="">

























</p><div style="margin: 0px; line-height: normal; font-family: menlo; color: rgb(207, 135, 36);" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(88,126,168)" class="">foo</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(88,126,168)" class="">handle</span><span style="font-variant-ligatures: no-common-ligatures;" class="">() </span><span style="font-variant-ligatures:no-common-ligatures" class="">// prints 1</span></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div></div><div style="font-family:menlo;font-size:11px;margin:0px;line-height:normal" class=""><br class=""></div></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Mon, Apr 24, 2017 at 2:15 PM, Kevin Nattinger <span dir="ltr" class="">&lt;<a href="mailto:swift@nattinger.net" target="_blank" class="">swift@nattinger.net</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="">This makes it more convenient to create them, sure, but how would you pass them around or extract the value&nbsp;in a type-safe manner?<div class=""><br class=""></div><div class="">e.g. now I can write:</div><div class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">enum</span><span style="font-variant-ligatures:no-common-ligatures" class=""> Thing&lt;T, U&gt; {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">case</span><span style="font-variant-ligatures:no-common-ligatures" class=""> thingOne(</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="">T</span><span style="font-variant-ligatures:no-common-ligatures" class="">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">case</span><span style="font-variant-ligatures:no-common-ligatures" class=""> thingTwo(</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="">U</span><span style="font-variant-ligatures:no-common-ligatures" class="">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px" class=""><div style="margin:0px;line-height:normal;color:rgb(0,132,0)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">// How do I require thingOne&lt;String&gt; or thingTwo&lt;Int&gt;?</span></div></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">func</span><span style="font-variant-ligatures:no-common-ligatures" class=""> handle(thing: </span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="">Thing</span><span style="font-variant-ligatures:no-common-ligatures" class="">&lt;</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa" class="">String</span><span style="font-variant-ligatures:no-common-ligatures" class="">, </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa" class="">Int</span><span style="font-variant-ligatures:no-common-ligatures" class="">&gt;) {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">switch</span><span style="font-variant-ligatures:no-common-ligatures" class=""> thing {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">case</span><span style="font-variant-ligatures:no-common-ligatures" class=""> .</span><span style="font-variant-ligatures:no-common-ligatures;color:#31595d" class="">thingOne</span><span style="font-variant-ligatures:no-common-ligatures" class="">(let s): </span><span style="font-variant-ligatures:no-common-ligatures;color:#3e1e81" class="">print</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:#d12f1b" class="">"string </span><span style="font-variant-ligatures:no-common-ligatures" class="">\</span><span style="font-variant-ligatures:no-common-ligatures;color:#d12f1b" class="">(</span><span style="font-variant-ligatures:no-common-ligatures" class="">s</span><span style="font-variant-ligatures:no-common-ligatures;color:#d12f1b" class="">)"</span><span style="font-variant-ligatures:no-common-ligatures" class="">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">case</span><span style="font-variant-ligatures:no-common-ligatures" class=""> .</span><span style="font-variant-ligatures:no-common-ligatures;color:#31595d" class="">thingTwo</span><span style="font-variant-ligatures:no-common-ligatures" class="">(let i): </span><span style="font-variant-ligatures:no-common-ligatures;color:#3e1e81" class="">print</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:#d12f1b" class="">"int </span><span style="font-variant-ligatures:no-common-ligatures" class="">\</span><span style="font-variant-ligatures:no-common-ligatures;color:#d12f1b" class="">(</span><span style="font-variant-ligatures:no-common-ligatures" class="">i</span><span style="font-variant-ligatures:no-common-ligatures;color:#d12f1b" class="">)"</span><span style="font-variant-ligatures:no-common-ligatures" class="">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">}</span></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div><div class="">With your proposed syntax:</div><div class=""><br class=""></div><div class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><div style="margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">enum</span><span style="font-variant-ligatures:no-common-ligatures" class=""> Thing {</span></div><div style="margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">case</span><span style="font-variant-ligatures:no-common-ligatures" class=""> thingOne&lt;T&gt;(T)</span></div><div style="margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">case</span><span style="font-variant-ligatures:no-common-ligatures" class=""> thingTwo&lt;T&gt;(T)</span></div><div style="margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">}</span></div><div style="margin:0px;line-height:normal;min-height:13px" class=""><br class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span></div><div style="margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">func</span><span style="font-variant-ligatures:no-common-ligatures" class=""> handle(thing: </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa" class="">Thing</span><span style="font-variant-ligatures:no-common-ligatures" class="">) {</span></div><div style="margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">switch</span><span style="font-variant-ligatures:no-common-ligatures" class=""> thing {</span></div><div style="margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">case</span><span style="font-variant-ligatures:no-common-ligatures" class=""> thingOne(let s):</span></div><div style="margin:0px;line-height:normal;color:rgb(0,132,0)" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures" class="">// What is the type of s?</span></div><div style="margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="">case</span><span style="font-variant-ligatures:no-common-ligatures" class=""> thingTwo&lt;</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa" class="">Int&gt;</span><span style="font-variant-ligatures:no-common-ligatures" class="">(let i):</span></div><div style="margin:0px;line-height:normal;color:rgb(0,132,0)" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures" class="">// is it even possible to write an exhaustive switch?</span></div><div style="margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin:0px;line-height:normal" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">}</span></div></div></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class=""><div class="h5"><div class="">On Apr 24, 2017, at 6:57 AM, Joshua Alvarado via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="m_8618778811508446095Apple-interchange-newline"></div></div><div class=""><div class=""><div class="h5"><div dir="ltr" class=""><div class=""><h1 style="box-sizing:border-box;margin:0px 0px 16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(234,236,239);color:rgb(36,41,46)" class=""><font face="arial, helvetica, sans-serif" size="2" class=""><span style="font-weight:normal" class="">Here is my pitch on adding generics to enum cases and not to the enum type itself. Let me know if you have an improvements or modifications lets open it to discussion thank you swiftys! :)</span></font></h1><h1 style="box-sizing:border-box;margin:0px 0px 16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol'" class="">Enum with generic cases</h1><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px" class=""><li style="box-sizing:border-box" class="">Proposal:&nbsp;<a href="https://github.com/lostatseajoshua/swift-evolution/blob/master/NNNN-enum-generic-cases.md" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration:none" target="_blank" class="">SE-NNNN</a></li><li style="box-sizing:border-box;margin-top:0.25em" class="">Authors:&nbsp;<a href="https://github.com/alvaradojoshua0" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration:none" target="_blank" class="">Joshua Alvarado</a></li><li style="box-sizing:border-box;margin-top:0.25em" class="">Review Manager: TBD</li><li style="box-sizing:border-box;margin-top:0.25em" class="">Status:&nbsp;<span style="box-sizing:border-box;font-weight:600" class="">PITCH</span></li></ul><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px" class=""><em style="box-sizing:border-box" class="">During the review process, add the following fields as needed:</em></p><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px" class=""><li style="box-sizing:border-box" class="">Decision Notes:&nbsp;<a href="https://lists.swift.org/pipermail/swift-evolution/" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration:none" target="_blank" class="">Rationale</a>,&nbsp;<a href="https://lists.swift.org/pipermail/swift-evolution/" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration:none" target="_blank" class="">Additional Commentary</a></li><li style="box-sizing:border-box;margin-top:0.25em" class="">Bugs:&nbsp;<a href="https://bugs.swift.org/browse/SR-NNNN" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration:none" target="_blank" class="">SR-NNNN</a>,&nbsp;<a href="https://bugs.swift.org/browse/SR-MMMM" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration:none" target="_blank" class="">SR-MMMM</a></li><li style="box-sizing:border-box;margin-top:0.25em" class="">Previous Revision:&nbsp;<a href="https://github.com/apple/swift-evolution/blob/...commit-ID.../proposals/NNNN-filename.md" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration:none" target="_blank" class="">1</a></li><li style="box-sizing:border-box;margin-top:0.25em" class="">Previous Proposal:&nbsp;<a href="https://github.com/lostatseajoshua/swift-evolution/blob/master/XXXX-filename.md" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration:none" target="_blank" class="">SE-XXXX</a></li></ul><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol'" class=""><a id="m_8618778811508446095gmail-user-content-introduction" class="m_8618778811508446095gmail-anchor" href="https://github.com/lostatseajoshua/swift-evolution/tree/master#introduction" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"></a>Introduction</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px" class="">This proposal adds a change to the enumeration type that allows an enum case to cast a generic on its associated value.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px" class="">Swift-evolution thread:&nbsp;<a href="https://lists.swift.org/pipermail/swift-evolution/" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration:none" target="_blank" class="">Discussion thread topic for that proposal</a></p><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol'" class=""><a id="m_8618778811508446095gmail-user-content-motivation" class="m_8618778811508446095gmail-anchor" href="https://github.com/lostatseajoshua/swift-evolution/tree/master#motivation" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"></a>Motivation</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px" class="">Enums currently support generics, but they are added onto the type itself. This can cause adverse syntax when implementing generics for associated values to be stored along each case. The enum case holds the associated value (not the enum type itself) so should create its own value constraints.</p><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol'" class=""><a id="m_8618778811508446095gmail-user-content-proposed-solution" class="m_8618778811508446095gmail-anchor" href="https://github.com/lostatseajoshua/swift-evolution/tree/master#proposed-solution" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"></a>Proposed solution</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px" class="">The generic is to be casted on the case of the enum and not on the enum itself.</p><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol'" class=""><a id="m_8618778811508446095gmail-user-content-detailed-design" class="m_8618778811508446095gmail-anchor" href="https://github.com/lostatseajoshua/swift-evolution/tree/master#detailed-design" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"></a>Detailed design</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px" class="">Current implementation:</p><div class="m_8618778811508446095gmail-highlight m_8618778811508446095gmail-highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px"><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,'liberation mono',menlo,courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal" class=""><span class="m_8618778811508446095gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_8618778811508446095gmail-pl-c" style="box-sizing:border-box">//</span> enum with two generic types</span>
<span class="m_8618778811508446095gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">enum</span> <span class="m_8618778811508446095gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">Foo</span>&lt;<span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">T</span>: <span class="m_8618778811508446095gmail-pl-e" style="box-sizing:border-box;color:rgb(121,93,163)"><span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">Hashable</span></span>, <span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">U</span>: <span class="m_8618778811508446095gmail-pl-e" style="box-sizing:border-box;color:rgb(121,93,163)"><span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">Collection</span></span>&gt; {
    <span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">bar</span>(<span class="m_8618778811508446095gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)"><span class="m_8618778811508446095gmail-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">obj</span></span>: T)
    <span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">baz</span>(<span class="m_8618778811508446095gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)"><span class="m_8618778811508446095gmail-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">obj</span></span>: U)
}

<span class="m_8618778811508446095gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_8618778811508446095gmail-pl-c" style="box-sizing:border-box">//</span> U is to be casted but it is not even used</span>
<span class="m_8618778811508446095gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> foo<span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span> Foo<span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">&lt;</span><span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">String</span>, [<span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">String</span>]<span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">&gt;</span> <span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> .<span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">bar</span>(<span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">obj</span>: <span class="m_8618778811508446095gmail-pl-s" style="box-sizing:border-box;color:rgb(24,54,145)"><span class="m_8618778811508446095gmail-pl-pds" style="box-sizing:border-box">"</span>hash<span class="m_8618778811508446095gmail-pl-pds" style="box-sizing:border-box">"</span></span>)

<span class="m_8618778811508446095gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_8618778811508446095gmail-pl-c" style="box-sizing:border-box">//</span> Creating an optional enum, the generics have to be casted without a value set</span>
<span class="m_8618778811508446095gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_8618778811508446095gmail-pl-c" style="box-sizing:border-box">//</span> The casting is really not needed as the values should be casted not the enum</span>
<span class="m_8618778811508446095gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">var</span> foo1<span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span> Foo<span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">&lt;</span><span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">String</span>, [<span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">String</span>]<span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">&gt;?</span>

<span class="m_8618778811508446095gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_8618778811508446095gmail-pl-c" style="box-sizing:border-box">//</span> Collections don’t look great either</span>
<span class="m_8618778811508446095gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">var</span> foos <span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> [Foo<span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">&lt;</span><span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">String</span>, [<span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">String</span>]<span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">&gt;</span>]()
foos.<span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">append</span>(.<span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">bar</span>(<span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">obj</span>:<span class="m_8618778811508446095gmail-pl-s" style="box-sizing:border-box;color:rgb(24,54,145)"><span class="m_8618778811508446095gmail-pl-pds" style="box-sizing:border-box">"</span>hash<span class="m_8618778811508446095gmail-pl-pds" style="box-sizing:border-box">"</span></span>))</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px" class="">Proposed solution</p><div class="m_8618778811508446095gmail-highlight m_8618778811508446095gmail-highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px"><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,'liberation mono',menlo,courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal" class=""><span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">enum</span> <span class="m_8618778811508446095gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">Foo</span> {
    <span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">bar</span><span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">&lt;</span>T<span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span> <span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">Hashable</span><span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">&gt;</span>(<span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">obj</span>: T)
    <span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">baz</span><span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">&lt;</span>U<span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span> <span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">Collection</span><span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">&gt;</span>(<span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">obj</span>: U)
}

<span class="m_8618778811508446095gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_8618778811508446095gmail-pl-c" style="box-sizing:border-box">//</span> generic type inferred on T</span>
<span class="m_8618778811508446095gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">var</span> foo<span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span> Foo <span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> .<span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">bar</span>(<span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">obj</span>: <span class="m_8618778811508446095gmail-pl-s" style="box-sizing:border-box;color:rgb(24,54,145)"><span class="m_8618778811508446095gmail-pl-pds" style="box-sizing:border-box">"</span>hash<span class="m_8618778811508446095gmail-pl-pds" style="box-sizing:border-box">"</span></span>) 

<span class="m_8618778811508446095gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_8618778811508446095gmail-pl-c" style="box-sizing:border-box">//</span> doesn’t need to cast the generic on the optional enum</span>
<span class="m_8618778811508446095gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_8618778811508446095gmail-pl-c" style="box-sizing:border-box">//</span> the associated value will hold the cast</span>
<span class="m_8618778811508446095gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">var</span> foo1<span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span> Foo<span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">?</span> 

<span class="m_8618778811508446095gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_8618778811508446095gmail-pl-c" style="box-sizing:border-box">//</span> This also gives better syntax with collections of enums with associated types</span>
<span class="m_8618778811508446095gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">var</span> foos <span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> [Foo]()
foos.<span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">append</span>(.<span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">bar</span>(<span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">obj</span>: <span class="m_8618778811508446095gmail-pl-s" style="box-sizing:border-box;color:rgb(24,54,145)"><span class="m_8618778811508446095gmail-pl-pds" style="box-sizing:border-box">"</span>hey<span class="m_8618778811508446095gmail-pl-pds" style="box-sizing:border-box">"</span></span>)</pre></div><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol'" class=""><a id="m_8618778811508446095gmail-user-content-source-compatibility" class="m_8618778811508446095gmail-anchor" href="https://github.com/lostatseajoshua/swift-evolution/tree/master#source-compatibility" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"></a>Source compatibility</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px" class="">This may cause subtle breaking changes for areas in code with generic enum cases. The compiler could help with the change by finding the associated generic and updating the case with the new syntax.</p><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol'" class=""><a id="m_8618778811508446095gmail-user-content-alternatives-considered" class="m_8618778811508446095gmail-anchor" href="https://github.com/lostatseajoshua/swift-evolution/tree/master#alternatives-considered" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"></a>Alternatives considered</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px" class="">An alternative would be to extend the&nbsp;<code style="box-sizing:border-box;font-family:sfmono-regular,consolas,'liberation mono',menlo,courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.0470588);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">associatedtype</code>&nbsp;keyword to the enum type.</p><div class="m_8618778811508446095gmail-highlight m_8618778811508446095gmail-highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px"><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,'liberation mono',menlo,courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal" class=""><span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">enum</span> <span class="m_8618778811508446095gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">Foo</span> {
    <span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">associatedtype</span> T <span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> <span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">Hashable</span>
    <span class="m_8618778811508446095gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="m_8618778811508446095gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">bar</span>(<span class="m_8618778811508446095gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)"><span class="m_8618778811508446095gmail-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">obj</span></span>: T)
}</pre></div></div><div class=""><br class=""></div>Copy of proposal can be found here&nbsp;<a href="https://github.com/lostatseajoshua/swift-evolution/blob/master/NNNN-enum-generic-cases.md" target="_blank" class="">Swift proposal on github</a><div class=""><div class=""><br class=""></div>-- <br class=""><div class="m_8618778811508446095gmail_signature">Joshua Alvarado<div class=""><a href="mailto:alvaradojoshua0@gmail.com" target="_blank" class="">alvaradojoshua0@gmail.com</a></div></div>
</div></div></div></div><span class="">
______________________________<wbr class="">_________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-<wbr class="">evolution</a><br class=""></span></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div class="gmail_signature" data-smartmail="gmail_signature">Joshua Alvarado<div class=""><a href="mailto:alvaradojoshua0@gmail.com" target="_blank" class="">alvaradojoshua0@gmail.com</a></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=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></blockquote></div></div></blockquote></div><br class=""></body></html>