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

Jean-Marie Gaillourdet jmg at gaillourdet.net
Thu Oct 7 10:34:32 EDT 2010


On 06.10.2010, at 22:43, 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;

Then, there is an inconsistency between lambda-case and traditional case and people will start complaining about that.

Haskell98 is a very well thought out language with very few syntactiv warts. I'd avoid introducing new language extensions which do introduce new warts. Backwards compatibility is not so important, because GHC will hopefully make it optional. Even when an extended \{ p1 -> e1; p2 -> e2 } is part of Haskell 2012 GHC will probably support Haskell 2011 as well. Therefore, I'd worry less about backwards compatibility, but concentrate more on consistency and elegance. I.e I'll favor
\p1 p2 -> e1
 p3 p4 -> e2

Just my 2 cents.

-- Jean

More information about the Haskell-Cafe mailing list