<div dir="ltr"><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif">I have often wanted to use a guard in a lambda function and had thought it wasn't possible. But apparently the case construct allows a viable approach. Here is a silly example.</font></font></font><div>
<font class="Apple-style-span" color="#003333" face="'trebuchet ms', sans-serif"><br></font></div><div><font size="2"></font><font class="Apple-style-span" color="#003333" face="'trebuchet ms', sans-serif"><div>
<font class="Apple-style-span" face="'courier new', monospace">testCase = map </font></div><div><font class="Apple-style-span" face="'courier new', monospace"> (\xs -> case xs of </font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> [] -> "empty list"</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> [y] | y < 5 -> "small singleton" </font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> | otherwise -> "large singleton" </font></div><div><font class="Apple-style-span" face="'courier new', monospace"> _ -> "multi-element list")</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div></font><div><font color="#003333"><font size="2"><font class="Apple-style-span" face="'courier new', monospace"><br></font></font></font></div>
<div><font color="#003333"><font size="2"><font face="trebuchet ms,sans-serif"><div><font class="Apple-style-span" face="'courier new', monospace">> testCase [[], [2], [7], [1,2,3]]</font></div><div><font class="Apple-style-span" face="'courier new', monospace">["empty","small singleton","large singleton","multi-element list"]</font></div>
<div><br></div><div>It seems particularly useful to be able to include both patterns and guards in case expressions. I haven't seen this usage anywhere. Is it considered bad form?</div></font></font></font></div><div>
<div dir="ltr"><font><font face="'trebuchet ms', sans-serif"><i><font color="#003333"><br>-- Russ </font></i></font></font></div></div></div></div>