[Haskell-cafe] Re: Lambda-case / lambda-if

Dean Herington heringtonlacey at mindspring.com
Wed Oct 6 19:45:42 EDT 2010

At 4:43 PM -0400 10/6/10, Sterling Clover wrote:
>On Oct 6, 2010, at 5:39 AM, Simon Marlow wrote:
>>  A slightly different suggestion from Simon PJ and myself (we 
>>agreed on something syntax-related :-) is the following:
>>   \case 1 -> f
>>	2 -> g
>>  where the two-token sequence '\ case' introduces a new optional 
>>layout context, the body of which is exactly the same as in a case 
>>expression.  So you could also write
>>   \case { 1 -> f; 2 -> g }
>>  if you want.  Guards are allowed of course.
>>  * a bit more noisy than just \:  I'm not sure what the
>>    ramifications of having \ introduce a layout context
>>    on its own would be, but I suspect there would be difficulties.
>>    Certainly some existing code would fail to parse, e.g.
>>    (case e of [] -> \x -> x+1; (x:xs) -> \x -> x+2)
>\ introducing a layout context is a no-go because, as in the example 
>given, it breaks too much code. However, \case as described is 
>somewhat less powerful. In particular, \ with a layout context lets 
>us have multi-argument pattern matching, while both \case and "case 
>of" give only single argument pattern matching. I don't know if the 
>extra functionality is that important, but I don't see why we can't 
>provide for it anyway, as in:
>\case (x:xs) n -> go xs; _ n -> n;

I would also very much like to have multi-argument pattern matching, but in

     \case a b -> ...

it sure suggests to me that `a` should be applied to `b` before casing.


More information about the Haskell-Cafe mailing list