[Haskell-cafe] Re: Function Precedence

Chris Smith cdsmith at twu.net
Tue Apr 1 16:45:49 EDT 2008


PR Stanley wrote:
>>Should that be f (1 (2 3)), or ((f 1) 2) 3?
>          The latter, of course, but that's not really what I'm
> driving at. I'm asking why we can't have a function treated differently
> with regard to the precedence and associativity rules. f 1 2 is indeed
> ((f 1) 2). Why not f 1 g 2 == ((f 1) (g 2))?

Are you asking why one doesn't change the rules for all functions?  Or 
are you asking why Haskell doesn't include a system of user-defined 
precedence and associativity for function application so that one could 
declare that g binds more tightly than f?  I see good reasons for both 
questions, but I'm unsure which you mean.

In both cases, it comes down to consistency of the syntax rules.  In 
order for (f 1 g 2) to parse as (f 1) (g 2), one would have to do 
something surprising.  It's unclear what that is: perhaps treat literals 
differently from variables?  Somehow determine a precedence level for
(f 1)?  Or maybe favor shorter argument lists for grouping function 
application?

If you have a very clear kind of grouping that you think makes sense in 
all cases, feel free to mention it.  It seems unlikely to me, but perhaps 
everyone will agree, once they see it, that it is in fact better than the 
current parsing rules.

-- 
Chris Smith



More information about the Haskell-Cafe mailing list