<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 29 Nov 2016, at 18:41, Tony Allevato 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="">Default values and overloaded cases don't (and in fact, shouldn't) be conflated.<div class=""><br class=""></div><div class="">I support default values for associated values but I'm not yet ready to say I'm in favor of overloaded cases. There's no ambiguity because your Value.number example can't exist without overloads, and default values don't create parameter lists that could mismatch like that (there's still only one case, and it has all of the associated values regardless of how many you specify at the time you create it).</div><div class=""><br class=""></div><div class="">Small self-contained examples like Value are nice, but entirely hypothetical and a bit contrived. "Maybe the design of the API does not want something" is difficult to convince me—I'd prefer to see a significant real world situation where it's vital to have two cases with the same name with differently typed payloads, which can't be expressed in a different way. For example, in your Javascript example, I think the optionality of that Document would be far better expressed as an Optional&lt;Document&gt; with a default value of nil than creating an overload, and that solution introduces far less complexity to the language than would introducing arbitrary overloads.</div></div></div></blockquote><br class=""></div><div>Yeah, we shouldn’t confuse these issues. Default values for enum payloads are something I also really want (in Swift 4 phase 2). Here’s my use-case:</div><div><br class=""></div><div><pre style="box-sizing: border-box; font-family: 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(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-break: normal; color: rgb(51, 51, 51);" class=""><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">public</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">enum</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">ReadError</span> : <span class="pl-e" style="box-sizing: border-box; color: rgb(121, 93, 163);"><span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Error</span> </span>{
    <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">case</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">otherError</span>(<span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);"><span class="pl-smi" style="box-sizing: border-box; color: rgb(51, 51, 51);">description</span></span>: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span>, <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);"><span class="pl-smi" style="box-sizing: border-box; color: rgb(51, 51, 51);">location</span></span>: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">StaticString</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">?</span> = #function) <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// &lt;- currently an error, tuples can't have default values</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);"></span>}</pre><div class=""><br class=""></div></div><div class="">And yes, you can use #function as a default value:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><font face="Courier" class="">func doIt(_ str: String = #function) {</font></div><div class=""><font face="Courier" class="">&nbsp;print("Called from \(str)")&nbsp;</font></div><div class=""><font face="Courier" class="">}</font></div><div class=""><font face="Courier" class="">func myFunc() { doIt() }</font></div><div class=""><font face="Courier" class=""><br class=""></font></div><div class=""><font face="Courier" class="">doIt() &nbsp; &nbsp;// Prints “Called from __lldb_expr_1” in REPL</font></div><div class=""><font face="Courier" class="">myFunc() &nbsp;// Prints “Called from myFunc()”</font></div><div class=""><font face="Courier" class=""><br class=""></font></div></blockquote><div class=""><br class=""></div>I think that’s a more valuable use-case than overloaded values; so if they’re incompatible and we have to choose one, I’d go for default values.<div class=""><br class=""></div><div class="">- Karl</div></body></html>