[Haskell-cafe] Re: proposal: point free case expressions

Edward Kmett ekmett at gmail.com
Thu Nov 5 13:09:10 EST 2009

On Thu, Nov 5, 2009 at 10:59 AM, Stefan Monnier <monnier at iro.umontreal.ca>wrote:

> > We could really use a case statement in which we skip the scrutinee and
> make
> > (case of {})' be syntactic sugar for `(\x -> case x of {})'.
> > So we could write:
> >> myFunc = anotherFunc $ case of
> >> Left err -> print err
> >> Right msg -> putStrLn msg
> > A minor syntactical addition, a big win!
> Since this "case" really defines a function, it seems like it would make
> more sense to allow defining anonymous functions by pattern matching.
> I.e. instead of "case of", I think it should use "λ", "\", "fn", or ...

The problem with all of those options is that they introduce a new keyword
into the language and can potentially break existing code.

Eugene's \{ } avoids that by using a different hole in the grammar, but at
the expense of 'un-Haskelly' braces. That and I question how easy it would
be to get to parse, because a common idiom seems to be to parse patterns as
expressions before converting them to patterns to avoid certain other
ambiguities in the grammar, so this requires a { } expression, which may
introduce a lot more ambiguity and problems to the grammar than it would
seem at first glance.

-Edward Kmett
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091105/35eb9333/attachment.html

More information about the Haskell-Cafe mailing list