<div dir="ltr">Hi,<div><br></div><div>I also support Jon&#39;s proposal for standalone of { ... }. Seems to me clearer and more useful than the special &quot;\case&quot; construct.</div><div><br></div><div>I suppose &#39;of { ... }&#39; could be generalized to multiple arguments, so that</div>

<div>    of (Just x) (Just y) -&gt; x ++ y</div><div>would create an anonymous function of type &#39;Maybe String -&gt; Maybe String -&gt; String&#39;.</div><div><br></div><div>Considering the recent thread about partial functions:</div>


<div><a href="http://www.haskell.org/pipermail/haskell-cafe/2012-December/105445.html" target="_blank">http://www.haskell.org/pipermail/haskell-cafe/2012-December/105445.html</a><br></div><div>we could have variants of &#39;of&#39; to distinguish partial functions. For example, we could have something like &#39;ofFull&#39; that would require an exhaustive list of patterns, and something like &#39;ofPart&#39; that would instead produce results of type &#39;Maybe something&#39;. (Most likely we&#39;d have to think of better names for them.) For example:</div>

<div>  ofPart [x] [y] -&gt; x ++ y</div><div>would be of type &#39;[String] -&gt; [String] -&gt; Maybe String&#39;, returning `Nothing` if one of the input isn&#39;t a 1-element list - an approach similar to Scala&#39;s partial functions. &lt;<a href="http://www.scala-lang.org/api/current/scala/PartialFunction.html">http://www.scala-lang.org/api/current/scala/PartialFunction.html</a>&gt;</div>

<div><br></div><div>[Perhaps we could have &#39;of&#39; to work both ways - if the list of patterns would be exhaustive, the result would be pure. If it would be non-exhaustive, the result would be &#39;Maybe something&#39;. Of course &#39;case x of ...&#39; would still work as now, not caring about exhaustiveness. But I&#39;m not sure if this wouldn&#39;t be too error prone.]</div>

<meta http-equiv="content-type" content="text/html; charset=utf-8"><div><br></div><div>We could even generalize &#39;ofPart&#39; to work with any Alternative instance so that</div><div>  ofPart [x] [y] -&gt; x ++ y</div>
<div>
would be of type &#39;(Alternative f) =&gt; [String] -&gt; [String] -&gt; f String&#39;. Matching patterns would return results using &#39;pure&#39;, non-matching &#39;empty&#39;, and they would be all combined combined using &lt;|&gt;. &#39;empty&#39; would be returned if nothing matched. (Among other things, this could have some interesting consequences when overlapping patterns would be applied to &#39;Alternative []&#39;.) For example</div>

<div><br></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">fn = ofPart (Right 0) -&gt; 1</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">            (Right x) -&gt; x</font></div>

<div><br></div><div>would produce (using today&#39;s syntax):</div><div><br></div><div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">fn :: (Alternative f) =&gt; Either Bool Int -&gt; f Int</font></div>

<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">fn x = case x of { Right 0   -&gt; pure 1 ; _ -&gt; empty; } &lt;|&gt;</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">       case x of { Right x   -&gt; pure x ; _ -&gt; empty; } &lt;|&gt;</font></div>

<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">       empty</font></div></div><div><br></div><div><br></div><div>Best regards,</div><div>Petr</div><meta http-equiv="content-type" content="text/html; charset=utf-8">
<div class="gmail_extra"><br><br><div class="gmail_quote">2012/12/29 Tom Ellis <span dir="ltr">&lt;<a href="mailto:tom-lists-haskell-cafe-2013@jaguarpaw.co.uk" target="_blank">tom-lists-haskell-cafe-2013@jaguarpaw.co.uk</a>&gt;</span><br>



<blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div>On Thu, Nov 29, 2012 at 05:49:53PM +0000, Jon Fairbairn wrote:<br>



&gt; Ben Franksen &lt;ben.franksen at <a href="http://online.de" target="_blank">online.de</a>&gt; writes:<br>
&gt; &gt; just wanted to drop by to say how much I like the new lambda case extension.<br>
&gt; &gt; I use it all the time and I just *love* how it relieves me from conjuring up<br>
&gt; &gt; dummy variables, which makes teh code not only esier to write but also to<br>
&gt; &gt; read.<br>
&gt;<br>
</div>&gt; &gt; [...] should *definitely* go into Haskell&#39;13.<br>
[...]<br>
&gt; To me it seems obvious that if we are going to do this [...] we should do<br>
<div>&gt; it simply by making the &quot;case exp&quot; part of a case expression optional.<br>
&gt;<br>
</div>&gt;    of {alts...}<br>
<div>&gt;<br>
&gt; and we would then describe<br>
&gt;<br>
</div>&gt;    case e of {...}<br>
&gt;<br>
&gt; as syntactic sugar for<br>
&gt;<br>
&gt;    (of {...}) (e)<br>
<br>
My very belated and unsolicited layman&#39;s reply is that I am a strong<br>
supporter of Jon&#39;s position.  His suggestion is parsimonious and natural.<br>
Without wishing to start the discussion again, I disagree that it is<br>
bikeshedding.  One lesson I learned from Haskell is that syntax is much more<br>
important than I previously realised.<br>
<span><font color="#888888"><br>
Tom<br>
</font></span><div><div><br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br></div></div>