<div dir="ltr">It&#39;s kludgy, but we could have something like:<div><br></div><div>```</div><div>@defaultArgument(configuration = (), where R.Configuration == Void)</div><div>@defaultArgument(actionHandler = { _ in }, where R.Action == Never)</div><div><span style="font-size:12.800000190734863px">func makeResource(with configuration: R.Configuration, actionHandler: @escaping (R.Action) -&gt; Void) -&gt; R { ... }</span><br></div><div>```<br><div><br></div><div>I don&#39;t like that we&#39;d be setting a default argument on something lexically before even encountering it in the declaration, but it&#39;s serviceable.</div><div><br></div><div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Nov 24, 2017 at 8:36 PM, T.J. Usiyan via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">I am all for this. are many types where there is an obvious &#39;zero&#39; or &#39;default&#39; value and the ability to express &quot;use that when possible&quot; without an overload is welcome.<div><br></div><div><br></div><div>The best thing that I can think of right now, in terms of syntax, is actually using @overload</div><div><br></div><div>```</div><div><span class="gmail-"><div style="font-size:12.800000190734863px">struct ResourceDescription&lt;R: Resource&gt; {</div><div style="font-size:12.800000190734863px"><br></div><div style="font-size:12.800000190734863px">  func makeResource(with configuration: R.Configuration, actionHandler: @escaping (R.Action) -&gt; Void) -&gt; R </div></span><div style="font-size:12.800000190734863px"> @overload(R.Configuration == Void) func makeResource(actionHandler: @escaping (R.Action) -&gt; Void) -&gt; R</div><div style="font-size:12.800000190734863px">@overload(R.Action == Never)  func makeResource(with configuration: R.Configuration) -&gt; R</div><span class="gmail-"><div style="font-size:12.800000190734863px">{</div><div style="font-size:12.800000190734863px">    // create a resource using the provided configuration</div><div style="font-size:12.800000190734863px">    // connect the action handler</div><div style="font-size:12.800000190734863px">    // return the resource</div><div style="font-size:12.800000190734863px">  }</div><div style="font-size:12.800000190734863px">}</div></span></div><div>```</div><div><br></div><div><br></div><div>This isn&#39;t great though…</div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="gmail-h5">On Fri, Nov 24, 2017 at 6:11 PM, Matthew Johnson via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div><div class="gmail-h5"><div style="word-wrap:break-word"><div>As mentioned in my prior message, I currently have a PR open to update the generics manifesto (<a href="https://github.com/apple/swift/pull/13012" target="_blank">https://github.com/apple/swif<wbr>t/pull/13012</a>).  I removed one topic from that update at Doug Gregor’s request that it be discussed on the list first.  </div><div><br></div><div>The idea is to add the ability to make default arguments conditional (i.e. depend on generic constraints).  It is currently possible to emulate conditional default arguments using an overload set.  This is verbose, especially when several arguments are involved.  Here is an example use case using the overload method to emulate this feature:</div><div><br></div><div>```swift</div><div>protocol Resource {</div><div>  associatedtype Configuration</div><div>  associatedtype Action</div><div>}</div><div>struct ResourceDescription&lt;R: Resource&gt; {</div><div>  func makeResource(with configuration: R.Configuration, actionHandler: @escaping (R.Action) -&gt; Void) -&gt; R {</div><div>    // create a resource using the provided configuration</div><div>    // connect the action handler</div><div>    // return the resource</div><div>  }</div><div>}</div><div><br></div><div>extension ResourceDescription where R.Configuration == Void {</div><div>  func makeResource(actionHandler: @escaping (R.Action) -&gt; Void) -&gt; R {</div><div>    return makeResource(with: (), actionHandler: actionHandler)</div><div>  }</div><div>}</div><div><br></div><div>extension ResourceDescription where R.Action == Never {</div><div>  func makeResource(with configuration: R.Configuration) -&gt; R {</div><div>    return makeResource(with: configuration, actionHandler: { _ in })</div><div>  }</div><div>}</div><div><br></div><div>extension ResourceDescription where R.Configuration == Void, R.Action == Never {</div><div>  func makeResource() -&gt; R {</div><div>    return makeResource(with: (), actionHandler: { _ in })</div><div>  }</div><div>}</div><div><br></div><div>```</div><div><br></div><div>Adding language support for defining these more directly would eliminate a lot of boilerplate and reduce the need for overloads.  Doug mentioned that it may also help simplify associated type inference (<a href="https://github.com/apple/swift/pull/13012#discussion_r152124535" target="_blank">https://github.com/apple/swif<wbr>t/pull/13012#discussion_r15212<wbr>4535</a>).</div><div><br></div><div>The reason that I call this a pre-pitch and one reason Doug requested it be discussed on list is that I haven’t thought of a good way to express this syntactically.  I am interested in hearing general feedback on the idea.  I am also looking for syntax suggestions.</div><span class="gmail-m_-7331325194590092274HOEnZb"><font color="#888888"><div><br></div><div>Matthew</div></font></span></div><br></div></div>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>
<br>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
<br></blockquote></div><br></div></div></div></div>