<div><div dir="auto">Default values for associated types are approved for Swift 4. They just haven’t been implemented.</div><div dir="auto"><br></div><br><div class="gmail_quote"><div>On Tue, Jul 25, 2017 at 16:02 Matthew Johnson via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><blockquote type="cite"><div>On Jul 25, 2017, at 3:26 PM, David Sweeris via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br class="m_-2497074003022364047Apple-interchange-newline"><div><div dir="auto"><div><br></div><div>On Jul 25, 2017, at 12:38, Robert Bennett via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div>Currently if you have the following enum:<div><br></div><div>enum E&lt;T&gt; {<br><span class="m_-2497074003022364047Apple-tab-span" style="white-space:pre-wrap">        </span>case c(T)<br>}</div><div><br></div><div>then if T is Void, you have to write one of the following:</div><div><br></div><div><font face="Inconsolata">let x: E&lt;Void&gt; = .c(Void())</font></div><div><font face="Inconsolata">let y: E&lt;Void&gt; = .c(())</font></div><div><br></div><div>Looks awkward, no? In this case you can omit `&lt;Void&gt;` after `E` because it can be inferred, but if writing a (non-generic) function taking an argument of type `E&lt;Void&gt;`, then the `&lt;Void&gt;` cannot be omitted, and you still have to write `.c(())` for the case name.</div><div><br></div><div>I’m proposing that for enum cases with a single associated value of Void type, or of a generic type that is equal to Void in some instance, you may omit the parentheses altogether and merely write</div><div><br></div><div>let x: E&lt;Void&gt; = .c</div><div><br></div><div>The rationale is twofold: first, double parentheses just looks bad; second, there is only a single value of type Void, which means the associated value of `.c` is trivially inferable, and hence should be omissible.</div><div><br></div><div>I am not proposing that a bare `E.c` imply a type of `E&lt;Void&gt;` — `E.c` should still be illegal in the absence of specification of the generic type — only that when the type is known to be `E&lt;Void&gt;`, `.c` can replace `.c(())`.</div><div><br></div><div>Thoughts?</div></div></blockquote><br><div>My first response is +1</div><div><br></div><div>My second response is to ask just how much would it break things to expand this and allow omitting the argument anywhere its type is known to be Void? Maybe by implicitly providing a default value of `()` wherever there&#39;s a `Void` argument? Like make `func foo(x: Void) {...}` implicitly become `<span style="background-color:rgba(255,255,255,0)">func foo(x: Void = ()) {...}`?</span> I have a sneaking suspicion that this question&#39;s already been asked, but I&#39;m not sure.</div></div></div></blockquote><div><br></div></div></div><div style="word-wrap:break-word"><div><div>I think default arguments for associated values have come up before.  I would love to see that added someday.</div></div></div><div style="word-wrap:break-word"><div><br><blockquote type="cite"><div><div dir="auto"><div><br></div><div>- Dave Sweeris</div></div>_______________________________________________<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" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div></div>_______________________________________________<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/mailman/listinfo/swift-evolution</a><br>
</blockquote></div></div>