<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 Sep 12, 2016, at 12:04 PM, Douglas Gregor <<a href="mailto:dgregor@apple.com" class="">dgregor@apple.com</a>> wrote:</div><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Sep 12, 2016, at 8:14 AM, Paul Cantrell <<a href="mailto:cantrell@pobox.com" class="">cantrell@pobox.com</a>> wrote:</div></blockquote><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span class="" style="color: rgb(102, 139, 73); font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="color: rgb(102, 139, 73); font-variant-ligatures: no-common-ligatures;">// ...but this, oh dear:</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; color: rgb(88, 126, 168);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">Optional</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures: no-common-ligatures" class="">None</span><span style="font-variant-ligatures: no-common-ligatures;" class="">: </span><span style="font-variant-ligatures: no-common-ligatures" class="">JSONRepresentable</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> { }</span></div></div></div></div></div></blockquote><div class=""><br class=""></div><div class="">This will be ill-formed; Optional.None isn’t a type, it’s part of the value, and allowing the conformance to be present or absent based on a run-time value is a massive complication:</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><font face="Menlo" class=""> func f<T: JSONRepresentable>(_: T) { }</font></div><div class=""><font face="Menlo" class=""> func g(stringOpt: String?) { f(stringOpt) } // whether the conformance applies or not depends on the run-time value!</font></div></div></div></div></blockquote><div><br class=""></div><div>Got it. This is more or less what I meant by “oh dear,” but better spelled out.</div><div><br class=""></div><div>Two thoughts pop up from your response:</div><div><br class=""></div><div>1. I just realized that my <span class="" style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(50, 62, 125);">extension</span><span class="" style="color: rgb(88, 126, 168); font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="color: rgb(88, 126, 168); font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;">Optional</span><span class="" style="color: rgb(88, 126, 168); font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;">.</span><span class="" style="color: rgb(88, 126, 168); font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;">None</span> is totally unnecessary. This covers nil as well as wrapped values:</div><div><br class=""></div><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(88, 126, 168);"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(50, 62, 125);"> extension</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-variant-ligatures: no-common-ligatures;">Optional</span><span class="" style="font-variant-ligatures: no-common-ligatures;">: </span><span class="" style="font-variant-ligatures: no-common-ligatures;">JSONRepresentable</span></div></div></div></div></div><div><span class="" style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(50, 62, 125);">where</span><span class="" style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;"> Wrapped: JSONRepresentable</span> </div><div><br class=""></div><div>…and there’s no need to special-case nil.</div><div><br class=""></div><div>I still fall into the trap of forgetting that in Swift, different nils can have different types. I still vaguely think of there being a single-value NilType (wrong) that’s a subtype (wrong) of all reference types (wrong). Old habits die hard!</div><div><br class=""></div><div>2. That notwithstanding, I’ve come across a few cases where it would be useful to have individual enum cases either be different subtypes of their enclosing enum type, or conform to different protocols. I’ll post next time I hit a useful example of that situation.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div class=""><div dir="auto" class=""><div class=""><div style="direction: inherit;" class="">It won't have support for protocols conforming to other protocols, though. </div></div></div></div></blockquote><br class=""></div>Curious. Why not? (I’ll happily wait for the proposal if you explain it there.)</div></div></blockquote><br class=""></div><div class="">The generics manifesto has a sketch of the reason; I will elaborate in the proposal.</div></div></div></blockquote><br class=""></div><div>I await it with patient excitement. :)</div><div><br class=""></div><div>Cheers, P</div><div><br class=""></div><br class=""></body></html>