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

Sterling Clover s.clover at gmail.com
Wed Oct 6 16:43:47 EDT 2010


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;

Cheers,
Sterl.


More information about the Haskell-Cafe mailing list