[Haskell-cafe] Syntax for lambda case proposal could be "\of"

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Wed Aug 15 14:49:49 EDT 2007


On Wed, 2007-08-15 at 11:06 -0700, Stefan O'Rear wrote:

> > Why not just:
> > 
> > sumTo0 = foldr (\0 k -> 0
> >                  n k -> n + k) 0
> 
> Because it would break a very large amount of old code, and I think H'
> was supposed to be upward compatible:

Aye, that'd be bad.

> foo = getSomethingCPS $ \ arg ->
>       moreStuff
>
> is now a syntax error (\ { varid -> } matches no productions).

I'm not sure I follow.

The patterns would have to match up in a column, so

foo = getSomethingCPS $ \ arg ->
      moreStuff

should be fine, to add another alternative it'd have to be:

foo = getSomethingCPS $ \ Pat1 ->
      moreStuff
                          Pat2 ->
      evenMoreStuff

This case might be tricky though:

foo = getSomethingCPS $ \ Pat1 -> foo
                          moreStuff

since we have to parse all of the moreStuff expression before
discovering it has no following "->" and so it's party of the body of
the first lambda alternative rather than a pattern starting a new
alternative.

I'm no parsing expert (especially when it comes to layout rules),
perhaps this is all too tricky.

Duncan



More information about the Haskell-Cafe mailing list