[Haskell-cafe] Re: Function Precedence

PR Stanley prstanley at ntlworld.com
Tue Apr 1 17:07:00 EDT 2008


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.

Paul:
All you'd have to do is to give the inner most function the highest precdence
therefore
f g x == f (g x)
let f x = x^2
let g x = x`div`2
f g 4 == error while
f (g 4) == 4

I'm beginning to wonder if I fully understand the right associativity 
rule for the -> operator.

Cheers, Paul



More information about the Haskell-Cafe mailing list