<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=""><div class="">I would like explicit specialization as well.</div><div class=""><br class=""></div><div class="">For historical interest, there is a blurb in the generics design document describing the original rationale (<a href="https://github.com/apple/swift/blob/master/docs/Generics.rst" class="">https://github.com/apple/swift/blob/master/docs/Generics.rst</a>, "Type Parameter Deduction").</div><div class=""><br class=""></div><div class="">Austin</div><br class=""><div><blockquote type="cite" class=""><div class="">On May 25, 2016, at 8:39 PM, David Sweeris 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=""><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="">On May 25, 2016, at 6:17 PM, David Hart via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><div class=""><blockquote type="cite" class=""><br class="Apple-interchange-newline"><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="">Hello,<div class=""><br class=""></div><div class="">This is a new pitch to allow explicitly specializing generic functions. Notice that potential ambiguity with initialisers and how I’m currently trying to avoid it. Please let me know what you think!</div></div></div></blockquote></div><br class=""><div class="">+1111!1eleventyone!</div><div class=""><br class=""></div><div class="">I’ve always wondered why that was disallowed in the first place… In any case, it’ll make it easier to work with functions in which the generic parameter only appears in the return signature. The current workaround is to pass in a “dummy” variable like so:</div><div class=""><div style="margin: 0px; line-height: normal; font-family: 'Fira Mono';" class=""><span style="color: rgb(211, 54, 130); font-variant-ligatures: no-common-ligatures;" class="">func</span><span style="color: rgb(147, 161, 161); font-variant-ligatures: no-common-ligatures;" class=""> foo <T</span><span style="color: rgb(147, 161, 161); font-variant-ligatures: no-common-ligatures;" class="">> (</span><span style="color: rgb(211, 54, 130); font-variant-ligatures: no-common-ligatures;" class="">_</span><span style="color: rgb(147, 161, 161); font-variant-ligatures: no-common-ligatures;" class="">: </span><span style="color: rgb(41, 161, 152); font-variant-ligatures: no-common-ligatures;" class="">T</span><span style="color: rgb(147, 161, 161); font-variant-ligatures: no-common-ligatures;" class="">.Type) -> </span><span style="color: rgb(41, 161, 152); font-variant-ligatures: no-common-ligatures;" class="">T</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#93a1a1" class=""> {</font></span><span style="color: rgb(147, 161, 161); font-variant-ligatures: no-common-ligatures;" class="">}</span></div><div style="margin: 0px; line-height: normal; font-family: 'Fira Mono'; color: rgb(147, 161, 161);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> x = </span><span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">foo</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #278bd2" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div></div><div class="">or to use explicit type annotation:</div><div class=""><div style="margin: 0px; line-height: normal; font-family: 'Fira Mono'; color: rgb(147, 161, 161);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> foo <T</span><span style="font-variant-ligatures: no-common-ligatures" class="">> () -> </span><span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">T</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; line-height: normal; font-family: 'Fira Mono'; color: rgb(147, 161, 161);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> y: </span><span style="font-variant-ligatures: no-common-ligatures; color: #278bd2" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = </span><span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">foo</span><span style="font-variant-ligatures: no-common-ligatures" class="">()</span></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="">The first is annoying (although less so in Swift 3 since we won’t need the `.self` part anymore), the second requires creating a new variable which makes the code jarring, and the two are incompatible with each other since the signatures are different.</span></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="">Also, I’d think it’d simplify the compiler, since there’d be one less error condition.</span></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="">- Dave Sweeris</span></div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>