<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 23, 2017, at 10:41 AM, Trent Nadeau 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="">The proposal looks good to me with one possible concern. I'm leaning toward types that use the defaults should still require the angle brackets, X&lt;&gt;. This makes it clear that you're using a generic type. </div></div></blockquote><div><br class=""></div><div>What are the perceived benefits by making it explicit that you’re using a defaulted-or-inferred generic type? What important pieces of information would the presence of an explicit “&lt;&gt;” communicate to future readers/maintainers of the code?</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class="">That leads me to think that the examples Doug gave should be an error as the explicit types on the `let`s should either be omitted completely or fully specified (as X&lt;&gt;, X&lt;Double&gt;, X&lt;Int&gt;, etc.).</div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Mon, Jan 23, 2017 at 1:21 PM, Joe Groff via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><span class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 23, 2017, at 9:51 AM, Douglas Gregor via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="m_2740357066933401872Apple-interchange-newline"><div class=""><div style="word-wrap:break-word" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 23, 2017, at 7:55 AM, Srđan Rašić via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="m_2740357066933401872Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi Everyone,<div class=""><br class=""></div><div class="">I've opened a PR (<a href="https://github.com/apple/swift-evolution/pull/591" target="_blank" class="">https://github.com/apple/<wbr class="">swift-evolution/pull/591</a>)&nbsp;<wbr class="">proposing default generic arguments which I think would be nice addition to the language. They are also mentioned in "Generic manifesto".&nbsp;</div><div class=""><br class=""></div><div class="">The proposal is focusing around generic types. Generic functions are not coved by the proposal and I don't think that we need default generic arguments in generic functions as all the types are always part of the function signature so the compiler can always infer them. One corner case might be if using default argument values in which case support for default generic arguments in functions might be useful.</div></div></div></blockquote><div class=""><br class=""></div><div class="">The proposal looks fairly straightforward and reasonable. One thing to think about is how it interacts with type inference. For example, consider these examples:</div><div class=""><br class=""></div><div class=""><span class="m_2740357066933401872Apple-tab-span" style="white-space:pre-wrap">        </span>struct X&lt;T = Int&gt; { }</div><div class=""><br class=""></div><div class=""><span class="m_2740357066933401872Apple-tab-span" style="white-space:pre-wrap">        </span>func f1() -&gt; X&lt;Double&gt; { return X() }</div><div class=""><br class=""></div><div class=""><div class=""><span class="m_2740357066933401872Apple-tab-span" style="white-space:pre-wrap">        </span>func f2() -&gt; X&lt;Int&gt; { return X() }</div><div class=""><div class=""><span class="m_2740357066933401872Apple-tab-span" style="white-space:pre-wrap">        </span>func f2() -&gt; X&lt;Double&gt; { return X() }</div></div><div class=""><br class=""></div><div class=""><span class="m_2740357066933401872Apple-tab-span" style="white-space:pre-wrap">        </span>func f3&lt;T&gt;(_: T) -&gt; X&lt;T&gt; { return X() }</div><div class=""><br class=""></div></div><div class=""><span class="m_2740357066933401872Apple-tab-span" style="white-space:pre-wrap">        </span>let x1: X = f1() &nbsp; // okay: x1 has type X&lt;Double&gt;?</div><span class="m_2740357066933401872Apple-tab-span" style="white-space:pre-wrap">        </span>let x2: X = f2() &nbsp; // ambiguous?</div><div class=""><span class="m_2740357066933401872Apple-tab-span" style="white-space:pre-wrap">        </span>let x3a: X = f3(1.5) &nbsp; // okay: x3a has type X&lt;Double&gt;?</div><div class=""><div class=""><span class="m_2740357066933401872Apple-tab-span" style="white-space:pre-wrap">        </span>let x3b: X = f3(1) &nbsp; // okay: x3a has type X&lt;Int&gt;?</div><div class=""><br class=""></div>The type checker already has some notion of “if you can’t infer a particular type, fill in a default” that is used for literals. That rule could be used here… or we could do something else. This should be discussed in the proposal.</div><div class=""><br class=""></div><div class="">Thanks for working on this!</div></div></div></blockquote><br class=""></div></span><div class="">There's an interesting parallel to the default behavior of literals. The type of a number or string literal is inferred from type context, or falls back to a default type like Int or String if that doesn't come up with an answer. You could think of that of saying the 'Self' type of the protocol constraint has a default (and maybe that's how we'd generalize the "default type for a protocol" feature if we wanted to.) It makes sense to me to follow a similar model for generic parameter defaults; that way, there's one consistent rule that applies.</div><div class=""><br class=""></div><div class="">-Joe</div><br class=""></div><br class="">______________________________<wbr class="">_________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-<wbr class="">evolution</a><br class="">
<br class=""></blockquote></div><br class=""><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div class="gmail_signature" data-smartmail="gmail_signature">Trent Nadeau</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>