I'm in favor of both of these.<br><br>However, the issue outlined in (1) with respect to labels is problematic. The core team's post-Swift 3 plan (<a href="https://lists.swift.org/pipermail/swift-evolution-announce/2016-July/000233.html">https://lists.swift.org/pipermail/swift-evolution-announce/2016-July/000233.html</a>) for evolving from SE-0111 solves that problem without the need to invent new rules for (1). IMO, that issue should be addressed first, then (1).<br><div class="gmail_quote"><div dir="ltr">On Sun, Mar 26, 2017 at 14:04 David Sweeris via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">On Mar 26, 2017, at 11:12, Karl Wagner via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>> wrote:<br class="gmail_msg"><br class="gmail_msg"></div><blockquote type="cite" class="gmail_msg">I’d like to pitch the following two language changes. Both of them are technically possible today if you manually write thunks for the relevant protocol requirements, but it would be nice if we allowed them to be written directly:<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">1) Allow closures to satisfy function requirements in protocols</div><div class="gmail_msg"><br class="gmail_msg"></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class="gmail_msg"><div class="gmail_msg"><pre style="box-sizing:border-box;font-family:SFMono-Regular,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(246,248,250);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(36,41,46)" class="gmail_msg"><span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">protocol</span> <span class="m_-1316733808039533553pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">MyProtocol</span> {
<span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="m_-1316733808039533553pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">run</span>(<span class="m_-1316733808039533553pl-smi gmail_msg" style="box-sizing:border-box;color:rgb(51,51,51)">param</span>: <span class="m_-1316733808039533553pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Int</span>) <span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">-></span> <span class="m_-1316733808039533553pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">String</span>
}
<span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">struct</span> <span class="m_-1316733808039533553pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">MyStruct</span> : <span class="m_-1316733808039533553pl-e gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">MyProtocol </span>{
<span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">var</span> run <span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">:</span> (<span class="m_-1316733808039533553pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Int</span>)<span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">-></span><span class="m_-1316733808039533553pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">String</span> <span class="m_-1316733808039533553pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_-1316733808039533553pl-c gmail_msg" style="box-sizing:border-box">//</span> Satisfies requirement MyProtocol.run</span>
<span class="m_-1316733808039533553pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span>}</pre><div class="gmail_msg"><br class="gmail_msg"></div></div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class="gmail_msg">Among other things, it would make writing type-erased wrappers in the style of AnyCollection much easier. The only obvious niggle is that the argument label wouldn’t be required when invoking the closure directly. The labels have no type-system significance, but it does make it subtly easier to write less generic code than you intend do. We could solve this by having code-completion favour protocol methods in this situation, or simply to require the label when invoking a closure which implements a known protocol requirement.</blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div></blockquote>2) Allow functions with default parameters to satisfy function requirements in protocols<div class="gmail_msg"><br class="gmail_msg"></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class="gmail_msg"><div class="gmail_msg"><pre style="box-sizing:border-box;font-family:SFMono-Regular,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(246,248,250);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(36,41,46)" class="gmail_msg"><span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">protocol</span> <span class="m_-1316733808039533553pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">Sportsplayer</span> {
<span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="m_-1316733808039533553pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">goalsScored</span>() <span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">-></span> <span class="m_-1316733808039533553pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Int</span>
}
<span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">struct</span> <span class="m_-1316733808039533553pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">SoccerPlayer</span>: <span class="m_-1316733808039533553pl-e gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">Sportsplayer </span>{
<span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">struct</span> <span class="m_-1316733808039533553pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">GoalType</span> : <span class="m_-1316733808039533553pl-e gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">RawOptionSet </span>{
<span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">static</span> <span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> Shot <span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> <span class="m_-1316733808039533553pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">GoalType</span>(<span class="m_-1316733808039533553pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">0x1</span>)
<span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">static</span> <span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> Volley <span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> <span class="m_-1316733808039533553pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">GoalType</span>(<span class="m_-1316733808039533553pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">0x10</span>)
<span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">static</span> <span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> Header <span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> <span class="m_-1316733808039533553pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">GoalType</span>(<span class="m_-1316733808039533553pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">0x100</span>)
<span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">static</span> <span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> <span class="m_-1316733808039533553pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Any</span> <span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> <span class="m_-1316733808039533553pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">GoalType</span>(<span class="m_-1316733808039533553pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">0x111</span>)
}
<span class="m_-1316733808039533553pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_-1316733808039533553pl-c gmail_msg" style="box-sizing:border-box">//</span> Default value .Any means this conforms to Sportsplayer</span>
<span class="m_-1316733808039533553pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="m_-1316733808039533553pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">goalsScored</span>(<span class="m_-1316733808039533553pl-smi gmail_msg" style="box-sizing:border-box;color:rgb(51,51,51)"><span class="m_-1316733808039533553pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">type</span></span>: GoalType <span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> .<span class="m_-1316733808039533553pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Any</span>) {
<span class="m_-1316733808039533553pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_-1316733808039533553pl-c gmail_msg" style="box-sizing:border-box">//</span>...</span>
<span class="m_-1316733808039533553pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> }
}
<span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">struct</span> <span class="m_-1316733808039533553pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">Footballer</span>: <span class="m_-1316733808039533553pl-e gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">Sportsplayer </span>{
<span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">struct</span> <span class="m_-1316733808039533553pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">GoalType</span> : <span class="m_-1316733808039533553pl-e gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">RawOptionSet </span>{
<span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">static</span> <span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> Touchdown <span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> <span class="m_-1316733808039533553pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">GoalType</span>(<span class="m_-1316733808039533553pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">0x1</span>)
<span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">static</span> <span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> FieldGoal <span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> <span class="m_-1316733808039533553pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">GoalType</span>(<span class="m_-1316733808039533553pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">0x10</span>)
<span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">static</span> <span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> <span class="m_-1316733808039533553pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Any</span> <span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> <span class="m_-1316733808039533553pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">GoalType</span>(<span class="m_-1316733808039533553pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">0x11</span>)
}
<span class="m_-1316733808039533553pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_-1316733808039533553pl-c gmail_msg" style="box-sizing:border-box">//</span> Default value .Any means this conforms to Sportsplayer</span>
<span class="m_-1316733808039533553pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> <span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="m_-1316733808039533553pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">goalsScored</span>(<span class="m_-1316733808039533553pl-smi gmail_msg" style="box-sizing:border-box;color:rgb(51,51,51)"><span class="m_-1316733808039533553pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">type</span></span>: GoalType <span class="m_-1316733808039533553pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> .<span class="m_-1316733808039533553pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Any</span>) {
<span class="m_-1316733808039533553pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_-1316733808039533553pl-c gmail_msg" style="box-sizing:border-box">//</span>...</span>
<span class="m_-1316733808039533553pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span> }
}</pre><div class="gmail_msg"><br class="gmail_msg"></div></div><div class="gmail_msg">I often find that I want to add some optional, implementation-specific parameter to a function which implements a protocol requirement. That’s currently not possible, and it’s a bit annoying.</div></blockquote></blockquote><br class="gmail_msg"></div><div dir="auto" class="gmail_msg"><div class="gmail_msg">IIRC, the issue with #2 is that protocols specify declaration-site details, but default parameters are implemented at the call-site. At least I believe that statement was accurate about a year(ish) ago... Dunno if anything has changed since then.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">If it can be made to work, though, I'd be in favor of it, and I think #1 as well.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">- Dave Sweeris</div></div>_______________________________________________<br class="gmail_msg">
swift-evolution mailing list<br class="gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg">
</blockquote></div>