<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Nov 28, 2017, at 1:25 PM, Matthew Johnson <<a href="mailto:matthew@anandabits.com" class="">matthew@anandabits.com</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 Nov 28, 2017, at 3:18 PM, Slava Pestov <<a href="mailto:spestov@apple.com" class="">spestov@apple.com</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; line-break: after-white-space;" class=""><br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Nov 28, 2017, at 8:44 AM, Matthew Johnson <<a href="mailto:matthew@anandabits.com" class="">matthew@anandabits.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">func makeResource(</div><div style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""> with configuration: Configuration = () where Configuration == Void, </div><div style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""> actionHandler: @escaping (Action) -> Void = { _ in } where Action == Never</div><div style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">)</div></div></blockquote></div><br class=""><div class="">Similar question to the one I posed earlier — what happens if I’m using makeResource() from a generic context? Is the conditional default argument simply not available?</div></div></div></blockquote><div class=""><br class=""></div><div class="">Right. If the constraints are not met at the call site the default is not available. I think you understood, but looking at the example above I omitted the resource type parameter. It should read:</div><div class=""><br class=""></div><div class="">func makeResource<R: Resource>(<br class=""> with configuration: R.Configuration = () where R.Configuration == Void, <br class=""> actionHandler: @escaping (R.Action) -> Void = { _ in } where R.Action == Never<br class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space;"><div class=""><div class=""><div class="">)</div></div></div></div></div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">In this case, how is it different from defining some static overloads of makeResource(), some of which have default arguments and some of which are generic?</div></div></div></blockquote><div class=""><br class=""></div><div class="">From the point of view of the call site it is not different. The differences are that:</div><div class=""><br class=""></div><div class="">* the user is presented with a single API rather than several overloads</div></div></div></div></blockquote><div><br class=""></div>Is this less confusing than encountering a new ‘where’ clause on default arguments, which is probably rare enough that many users will spend months/years using Swift without seeing it?</div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class="">* the compiler doesn’t have to reason about an overload set which might improve build times, etc</div></div></div></div></blockquote><div><br class=""></div>They’re effectively equivalent, because we still have to decide which subset of the default arguments apply at a given call site by checking all combinations of constraints.</div><div><br class=""></div><div>Slava</div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">Slava</div></div></div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></body></html>