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

Eugene Kirpichov ekirpichov at gmail.com
Thu Nov 5 16:53:04 EST 2009


2009/11/5 Edward Kmett <ekmett at gmail.com>:
> 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.

Hey, the braces are not that un-Haskelly. After all, you already can
write "case x of {Left err -> ...; Right res -> ...}" - that's exactly
why I suggested this notation.
So, I am just suggesting to replace "case of" with "\" and that's all.

>
> -Edward Kmett
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>



-- 
Eugene Kirpichov
Web IR developer, market.yandex.ru


More information about the Haskell-Cafe mailing list