[Haskell-cafe] Re: Function Precedence
Chris Smith
cdsmith at twu.net
Tue Apr 1 19:20:56 EDT 2008
PR Stanley wrote:
> 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 afraid I still don't understand what you're proposing. How can
f g x mean f (g x), and yet f g 4 is different from f (g 4)?
Maybe it'll help to point out that using functions as first-class
concepts -- including passing them around as data -- is fundamental to
functional programming languages. In other words, anything in the world
could be a function, whether it's acting like a function right now or
not. So distinguishing between (f g 4) and (f 1 2) is probably not
wise. They either need to both parse like ((f g) 4), or they need to
both parse like (f (1 2)). It has been the experience of the Haskell,
ML, and other related languages that left associativity for function
application works best.
> I'm beginning to wonder if I fully understand the right associativity
> rule for the -> operator.
It just means that if I have a string of things separated by ->, I can
put parentheses around all but the leftmost one, and it doesn't change
the meaning.
--
Chris Smith
More information about the Haskell-Cafe
mailing list