query about precedence: "$", the lazy function application operator
Mark Phillips
mark@austrics.com.au
Thu, 30 May 2002 18:02:54 +0930
Hi,
As I understand it, function application has highest precedence
(10 even!) whereas $, the operator which does the same thing, has
lowest precedence (0 even!). But there's something that doesn't
make sense to me.
Suppose I have functions
f :: Int -> Int
f x -> x * x
g :: Int -> Int
g x -> x + 1
The lazy application operator "$" allows me to do:
f $ g x
instead of
f (g x)
But I don't understand why it works this way! Let me explain.
f is a function, and application has highest precedence, so unless
it sees a bracket, it should take the next thing it sees as an
argument. Lo and behold the next thing it sees is "$", which is
not a bracket! So it should try and apply f to argument $. But
oh dear, $ is a function (operator actually); it is not an Int
at all! So an error should be reported!
So what am I not understanding properly?
Thanks,
Mark.
--
Dr Mark H Phillips
Research Analyst (Mathematician)
AUSTRICS - Smarter Scheduling Solutions - www.austrics.com
Level 2, 50 Pirie Street, Adelaide SA 5000, Australia
Phone +61 8 8226 9850
Fax +61 8 8231 4821
Email mark@austrics.com.au