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

Brandon Michael Moore brandon at heave.ugcs.caltech.edu
Wed Aug 15 14:40:45 EDT 2007


On Wed, Aug 15, 2007 at 11:06:36AM -0700, Stefan O'Rear wrote:
> On Wed, Aug 15, 2007 at 06:58:40PM +0100, Duncan Coutts wrote:
> > On Wed, 2007-08-15 at 10:50 -0700, Stefan O'Rear wrote:
> > 
> > > OTOH, your proposal provides (IMO) much more natural syntax for
> > > multi-pattern anonymous functions, especially if we stipulate that
> > > unlike a case (but like a lambda) you can have multiple arguments; then
> > > you could write stuff like:
> > > 
> > > sumTo0 = foldr (\of 0 k -> 0
> > >                     n k -> n + k) 0
> > > 
> > > Anyone else like this?
> > 
> > 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:
> 
> foo = getSomethingCPS $ \ arg ->
>       moreStuff
> 
> is now a syntax error (\ { varid -> } matches no productions).

I was going to say you could leave the other production, but layout
is separated from parsing. It's not even simple to say "use nondeterminism",
because of that rule about a layout level ending if there would otherwise
be a parse error. If that parse error rule backtracks far enough, old lambdas
could simply have the production  \{} pat -> expr, if it's only one token
of lookahed perhaps \ { pat } -> expr would be mostly backwards-compatible
(but it would be very wierd to understand the errors when it wasn't).

Lambdas with multiple arguments and pattern matching sound really nice, but
"case of" and "\of" are both extremely ugly names. They only make sense if
you are familiar with the rest of the language and think of this as
shoehorning in some new kind of lambda with pattern matching (remember
 constructor classes, and how it's all just typeclasses now). What do the rest
of you on the cafe think?

If a different name is necessary, I'd prefer something like "fun" that just
tries to imply this is a slighly heavier, more powerful kind of anonymous function.
(plus it's a step towards rec-expressions)

Brandon


More information about the Haskell-Cafe mailing list