<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 Jan 27, 2017, at 1:43 PM, Anton Zhilin 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 dir="ltr" class=""><div class="markdown-here-wrapper" style=""><p style="margin:0px 0px 1.2em!important" class="">Current alternative to default generic arguments is <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="">typealias</code>, like <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="">basic_string</code> and <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="">string</code> in C++:</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px" class=""><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline;white-space:pre;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important" class="">struct BasicBigInt<T> { ... }
typealias BigInt = BasicBigInt<Int64>
</code></pre><p style="margin:0px 0px 1.2em!important" class="">It’s not <em class="">that</em> ugly. It keeps type inference rules simpler, easier to understand and more explicit.<br class="">As someone noted, current type inference for generic initializers works satisfactory in 99% cases. Is it really worth it to try to cover 99.9% at the cost of complexity of type inference rules?</p><p style="margin:0px 0px 1.2em!important" class="">On the other hand, in the wild, there may exist types with 3 or even more generic parameters that have sensible default values. [Research needed]<br class="">For such complex cases, I think, it makes sense to add default generic parameters <em class="">only</em> together with generic parameter labels.<br class="">Also, in such cases, functions on types could often help. And that story is even out of scope of Swift 4 Phase 2.</p></div></div></div></blockquote></div><div>If we could overload the type's name, I <i class="">think</i> that’d solve my use-case pretty much completely:</div><div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">protocol</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Endian {}</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">class</span><span style="font-variant-ligatures: no-common-ligatures" class=""> BigEndian : </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Endian</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; color: #bb2ca2" class="">class</span><span style="font-variant-ligatures: no-common-ligatures" class=""> LittleEndian : </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Endian</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; color: #bb2ca2" class="">class</span><span style="font-variant-ligatures: no-common-ligatures" class=""> NativeEndian : </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Endian</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {}</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">struct</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> BigInt<Chunk </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">_</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">: Integer, Endian </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">_</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">: Endian> {...} </span><span style="font-variant-ligatures: no-common-ligatures" class="">//Made-up syntax for indicating the generic parameters’ labels should be the same both internally and externally</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">typealias</span><span style="font-variant-ligatures: no-common-ligatures" class=""> BigInt<T> = BigInt<Chunk: <span style="color: rgb(79, 129, 135);" class="">T</span>, Endian: <span style="color: rgb(79, 129, 135);" class="">NativeEndian</span><span style="font-variant-ligatures: no-common-ligatures;" class="">> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">where</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> T: Integer</span></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">typealias</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> BigInt = </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">BigInt</span><span style="font-variant-ligatures: no-common-ligatures;" class=""><</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures;" class="">></span></div><div class=""><br class=""></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class="">- Dave Sweeris</span></div></div></body></html>