<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 9:51 AM, Douglas Gregor 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=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" 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 <<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="">Hi Everyone,<div class=""><br class=""></div><div class="">I've opened a PR (<a href="https://github.com/apple/swift-evolution/pull/591" class="">https://github.com/apple/swift-evolution/pull/591</a>) proposing default generic arguments which I think would be nice addition to the language. They are also mentioned in "Generic manifesto". </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="Apple-tab-span" style="white-space:pre">        </span>struct X<T = Int> { }</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>func f1() -> X<Double> { return X() }</div><div class=""><br class=""></div><div class=""><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>func f2() -> X<Int> { return X() }</div><div class=""><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>func f2() -> X<Double> { return X() }</div></div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>func f3<T>(_: T) -> X<T> { return X() }</div><div class=""><br class=""></div></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let x1: X = f1() // okay: x1 has type X<Double>?</div><span class="Apple-tab-span" style="white-space: pre;">        </span>let x2: X = f2() // ambiguous?</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>let x3a: X = f3(1.5) // okay: x3a has type X<Double>?</div><div class=""><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>let x3b: X = f3(1) // okay: x3a has type X<Int>?</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><div>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><br class=""></div><div>-Joe</div><br class=""></body></html>