<div dir="ltr">&gt; <span style="font-size:13px">I’m not a fan of the concise form, though, and would drop it.</span><div><span style="font-size:13px"><br></span></div><div>You mean &quot;case<b style="font-size:13px">s</b>&quot;, right? <span style="font-size:13px">I admit I find the syntax is a bit ugly, but if you have 20 cases to write, it&#39;s clearer. I&#39;ll bet any money that in day to day use, if this proposal is accepted, it&#39;s the short </span>form that 90% of us would use.</div><div><span style="font-size:13px"><br></span></div><div>My vote is that it stay in the proposal.<span style="font-size:13px"><br></span></div><div><span style="font-size:13px"><br></span></div><div><span style="font-size:13px"><br></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 14, 2016 at 2:32 PM, Thorsten Seitz via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hi Craig,<div><br></div><div>looks good so far!</div><div>I’m not a fan of the concise form, though, and would drop it.</div><div><br></div><div>The proposal should define what a partial function is supposed to be., i.e. a function that can check whether an argument is in its domain.</div><div>It should be possible to ask them isDefinedAt() like in Scala. And chain them with orElse() and andThen(). That would be really useful!</div><div><br></div><div><b>let</b> stdColorCode = {</div><span class=""><div><span style="white-space:pre-wrap">        </span><b>case</b> .Red: 100</div><div><span style="white-space:pre-wrap">        </span><b>case</b> .Green: 200</div><div><span style="white-space:pre-wrap">        </span><b>case</b> .Blue: 300</div><div>}</div><div><br></div></span><div>// type of stdColorCode: <b>partial</b> Color -&gt; Int</div><div>// or maybe: Color =&gt; Int</div><div><br></div><div><b>let</b> colorCode = stdColorCode.orElse {</div><div><span style="white-space:pre-wrap">        </span><b>case</b> .Yellow: 400</div><div><span style="white-space:pre-wrap">        </span><b>case</b> .Cyan: 500</div><div><span style="white-space:pre-wrap">        </span><b>case</b> .Magenta: 600</div><div>}</div><div><br></div><div><b>let</b> x = colorCode(col).orElse(700)</div><div><br></div><div>Thinking about it, I have the feeling that it should be possible to force exhaustiveness checks somehow.</div><div><br></div><div>Maybe like follows:</div><div><br></div><div>// Defining a partial function has to be made explicit with a new keyword <b>undefined</b> in the default clause (or other case clauses)</div><div>// (I briefly thought about reusing „continue“ but that might collide with the proposal to make „break“, „continue“ and possibly „return“ to</div><div>// work properly in closures)</div><div><div><b>let</b> stdColorCode = {</div><span class=""><div><span style="white-space:pre-wrap">        </span><b>case</b> .Red: 100</div><div><span style="white-space:pre-wrap">        </span><b>case</b> .Green: 200</div><div><span style="white-space:pre-wrap">        </span><b>case</b> .Blue: 300</div></span><div><span style="white-space:pre-wrap">        </span><b>default</b>: <b>undefined</b></div><div>}</div></div><div><br></div><div>// The following is *not* a partial function (and cannot be asked isDefinedAt() or chained).</div><div>// But the compiler would complain if the argument type (here inferred) has more cases (just like in a normal switch statement).</div><div><div><b>let</b> stdColorCode = {</div><span class=""><div><span style="white-space:pre-wrap">        </span><b>case</b> .Red: 100</div><div><span style="white-space:pre-wrap">        </span><b>case</b> .Green: 200</div><div><span style="white-space:pre-wrap">        </span><b>case</b> .Blue: 300</div></span><div><span style="white-space:pre-wrap">        </span><b>case</b> .Yellow: 400</div><div><span style="white-space:pre-wrap">        </span><b>case</b> .Cyan: 500</div><div><span style="white-space:pre-wrap">        </span><b>case</b> .Magenta: 600</div><div>}</div></div><div><br></div><div>-Thorsten</div><div><br></div><div><div><br></div><div><blockquote type="cite"><div><div class="h5"><div>Am 14.01.2016 um 20:23 schrieb Craig Cruden via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;:</div><br></div></div><div><div><div class="h5"><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Paul, </div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">I tried to put my understanding on the latest proposal option into a draft on github (instead of my usual BitBucket repo).  </span><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Take a look at it and see if there is anything useable.</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="https://github.com/cacruden/swift-evolution/blob/master/proposals/0000-Pattern-Matching-Partial-Function.md" target="_blank">https://github.com/cacruden/swift-evolution/blob/master/proposals/0000-Pattern-Matching-Partial-Function.md</a></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Craig</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br><div><blockquote type="cite"><div>On 2016-01-11, at 14:17:09, Craig Cruden &lt;<a href="mailto:ccruden@novafore.com" target="_blank">ccruden@novafore.com</a>&gt; wrote:</div><br><div><div style="word-wrap:break-word">Ignore the last comment - tired and mistaken. :p<div><br></div><div><br><div><blockquote type="cite"><div>On 2016-01-11, at 14:16:01, Craig Cruden &lt;<a href="mailto:ccruden@novafore.com" target="_blank">ccruden@novafore.com</a>&gt; wrote:</div><br><div><div style="word-wrap:break-word">I just realized “cases” probably is not needed - if it see’s a comma after case but before “:” then it is the concise form.  <div><br></div><div>If the switch / case can do that , the partial function case should be able to do the same thing.</div><div><br></div><div><br><div><blockquote type="cite"><div>On 2016-01-11, at 13:23:19, Craig Cruden &lt;<a href="mailto:ccruden@novafore.com" target="_blank">ccruden@novafore.com</a>&gt; wrote:</div><br><div><div style="word-wrap:break-word"><div>I have thought about it a bit more and I think this would cover all the cases that interest me (in addition to others needs for a little more conciseness on the most simple case).  </div><div><br></div><div>I also think we need to be clear that the “case” (or cases) and “default” are is really just a partial function which in it’s entirety is really just a complete function for used wherever a complete function (exhaustive) can be passed (e.g. reduce, filter, etc.) - otherwise they might get confused on why we are adding it to “map”.  </div><div><br></div><div>The optional where clause should also be part of the case clause as part of the proposal.  </div><div><br></div><div>There would be no need for statement based “fallthrough”.</div><div><br></div><div>You mentioned your proposal….  have you drafted a formal proposal draft?</div><div><br></div><div><br></div><br><div><blockquote type="cite"><div>On 2016-01-10, at 12:41:03, Paul Ossenbruggen via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div>I agree that it would be really useful to keep things concise. I am going to suggest again an idea I had in the past, it is also in my proposal, which might work well for this problem. This might address the verbosity of the “case” and at the same time make it obvious we are dealing with a switch expression. So both would be valid: <div><br></div><div><div><div dir="ltr"><div style="word-wrap:break-word"><div dir="ltr"><div style="word-wrap:break-word"><div dir="ltr"><div style="font-size:13px;margin:0px;line-height:normal;font-family:Arial"><b><div dir="ltr" style="font-family:Helvetica;font-size:12px;font-weight:normal"><div style="word-wrap:break-word"><div dir="ltr"><div style="word-wrap:break-word"><div dir="ltr"><b style="font-family:Arial;font-size:13px"><b><span style="color:rgb(96,96,96);white-space:pre-wrap">        </span><font color="#006d8f">let</font></b><b style="color:rgb(96,96,96)"> num = color.</b><font color="#008cb4">map </font>{</b></div></div></div></div></div></b></div></div></div></div></div></div></div></div></div></blockquote><blockquote type="cite"><b style="font-family:Arial;font-size:13px"><b style="color:rgb(96,96,96)"><span style="white-space:pre-wrap">        </span></b><b><span style="white-space:pre-wrap"><font color="#606060">        </font><font color="#006d8f">cases</font><font color="#606060">   </font></span></b><b><font color="#4f7a28">.Red:</font></b><b style="color:rgb(227,36,0)"> </b><b style="color:rgb(96,96,96)">100,</b><b style="color:rgb(96,96,96)"> </b></b><br><b style="font-family:Arial;font-size:13px"><b style="color:rgb(96,96,96)"><span style="white-space:pre-wrap">        </span></b><b><span style="white-space:pre-wrap"><font color="#606060">        <span style="white-space:pre-wrap">        </span>     </font><font color="#4f7a28">.</font></span></b><b><font color="#4f7a28">Green: </font></b><span> </span><b style="color:rgb(96,96,96)">200</b><b><font color="#e32400">,</font></b><b style="color:rgb(96,96,96)"> </b></b><br><b style="font-family:Arial;font-size:13px"><b style="color:rgb(96,96,96)"><span style="white-space:pre-wrap">        </span></b><b style="color:rgb(96,96,96)"><span style="white-space:pre-wrap">        <span style="white-space:pre-wrap">        </span>     </span></b><b><font color="#4f7a28">.Blue</font><font color="#e32400">: </font></b><b style="color:rgb(96,96,96)">300</b></b><br><b style="font-family:Arial;font-size:13px"><b style="color:rgb(96,96,96)"><span style="white-space:pre-wrap">        </span></b><b><span style="white-space:pre-wrap"><font color="#606060">        </font><font color="#006d8f">default</font></span></b><b style="color:rgb(227,36,0)">: </b><b style="color:rgb(96,96,96)">-1</b><b style="color:rgb(227,36,0)"> </b></b><br><b style="font-family:Arial;font-size:13px"><span style="color:rgb(227,36,0);white-space:pre-wrap">        </span>}</b><br><b style="font-family:Arial;font-size:13px"><b><span style="color:rgb(96,96,96);white-space:pre-wrap">        </span><font color="#006d8f">let</font></b><b style="color:rgb(96,96,96)"> num = color.</b><b><font color="#008cb4">map </font>{</b></b><br><b style="font-family:Arial;font-size:13px"><b style="color:rgb(96,96,96)"><span style="white-space:pre-wrap">        </span></b><b><span style="white-space:pre-wrap"><font color="#606060">        </font><font color="#006d8f">case</font><font color="#606060">     </font></span></b><b><font color="#4f7a28">.Red:</font></b><b style="color:rgb(227,36,0)"> </b><b style="color:rgb(96,96,96)">100</b></b><br><b style="font-family:Arial;font-size:13px"><b style="color:rgb(96,96,96)"><span style="white-space:pre-wrap">        </span></b><b><span style="white-space:pre-wrap"><font color="#606060">        </font><font color="#006d8f">case   </font><font color="#606060">  </font><font color="#4f7a28">.</font></span></b><b><font color="#4f7a28">Green: </font></b><span style="font-family:Helvetica"> </span><b style="color:rgb(96,96,96)">200</b><b style="color:rgb(96,96,96)"> </b></b><br><b style="font-family:Arial;font-size:13px"><b style="color:rgb(96,96,96)"><span style="white-space:pre-wrap">        </span></b><b><span style="white-space:pre-wrap"><font color="#606060">        </font><font color="#006d8f">case</font><font color="#606060">     </font></span></b><b><font color="#4f7a28">.Blue</font><font color="#e32400">: </font></b><b style="color:rgb(96,96,96)">300</b></b><br><b style="font-family:Arial;font-size:13px"><b style="color:rgb(96,96,96)"><span style="white-space:pre-wrap">        </span></b><b><span style="white-space:pre-wrap"><font color="#606060">        </font><font color="#006d8f">default</font></span></b><b style="color:rgb(227,36,0)">: </b><b style="color:rgb(96,96,96)">-1</b><b style="color:rgb(227,36,0)"> </b></b><br><div style="word-wrap:break-word"><div><div><div><div><div style="word-wrap:break-word"><div><div><div><div><div><div><div><div style="word-wrap:break-word"><div><div><div><div dir="ltr"><div style="word-wrap:break-word"><div dir="ltr"><div style="word-wrap:break-word"><div dir="ltr"><div style="font-size:13px;margin:0px;line-height:normal;font-family:Arial"><b><span style="color:rgb(227,36,0);white-space:pre-wrap">        </span>}</b></div><div><b><br></b></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></blockquote></div><br></div></div></blockquote></div><br></div></div></div></blockquote></div><br></div></div></div></blockquote></div><br></div></div></div><span class=""><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=1MXK54sosN3xru3iYcLt0oBZ2w20i49gyogXctgrspfaDNrb6v-2FQSoGuGh4xjx2M1VLzhvKFmvFBNKS228NkpniExzVjzphDHKrHnSn-2F22p-2FW-2BpWCX4bCmdHq4Peogpqn1Ijqn3IZ-2FZhlfw7732DzkvsKcYFZv5NhFB-2BztZrT-2FnqS0lq4vx5caUE-2B3mYjzsDiA2zC5aYFPtvAaj9H22xzZgvxjWw8tuDBqXl22a3R7U-3D" alt="" width="1" height="1" border="0" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;min-height:1px!important;width:1px!important;border-width:0px!important;margin:0px!important;padding:0px!important"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important"><span> </span></span><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">_______________________________________________</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">swift-evolution mailing list</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="mailto:swift-evolution@swift.org" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">swift-evolution@swift.org</a><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span></div></blockquote></div><br></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=l3fs1g-2F466j3y5fD5Q61KddsTTCmXL0uxw3XoAMFFNj55EzGnZii-2F9Y-2F2aRoK6j62wYn7JMJ8yQNJbBMNlkGzaHn9YgxfKAOqC5G1I4sbqftyJkFfbWvkevc5L1Z-2FK9Ee-2FQmce70NuRGJgX4tsWdBeVqMe6kahIsDq2pEFUFvi6TL2DOz3eXJRItrGW5FLm4F2rcSOMiOXLdaWbqvepk0HMmeJvAP50DcSXn5R599PM-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
</div>
<br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">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>
<br></blockquote></div><br></div>