[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: SYNTAX ONLY
Original-Via: uk.ac.nsf; Wed, 13 Mar 91 22:04:57 GMT
Date: Wed, 13 Mar 91 11:27:55 MST
From: Joe Fasel <jhf@chaco.c3.lanl.gov>
To: haskell <haskell%edu.yale.cs@yalevm.ycc.yale.edu>
Subject: Re: SYNTAX ONLY
Original-Sender: jhf <jhf%gov.lanl.c3.chaco%edu.yale.ycc.yalevm%edu.yale.cs@yale.edu>
Sender: haskell-request@cs.glasgow.ac.uk
Paul:
| Regarding precedence of prefix minus:
| -------------------------------------
| Yikes -- so many contradictory opinions!! After Brian's message I am
| beginning to believe that there really is no firm consensus on this
| issue; on the other hand Phil's message reminded me that the
| precedence of +, -, etc., being in PreludeCore, can't be redefined.
OK--Here's my last word on the subject: ;-)
I do believe that making the precedence of prefix - the same as +
is the choice most consistent with traditional mathematical notation.
Yes, mathematical notation is two-dimensional, and therefore a slightly
different beast, but I think we do think of superscripts as binding
most tightly, juxtaposition next, and then infix + and -, thus justifying
Fortran's choice of precedences for **, *, +, -, and the corresponding
operators in most programming languages since. One of the physicists
in my group put the situation to me very well: When he sees
-x^2+y
he thinks of
2
- x + y
and is disturbed to find that this is not equivalent to y-x^2 .
It does no good to tell him that he could have just written y-x^2
in the first place, since there is another mathematical convention
at work here: the lexicographic ordering of terms in a polynomial.
The polynomial
2 2
- x + 2xy - y
is likely to be rendered - x^2 + 2*x*y - y^2 , and it is difficult to
remember that what we think of as the first term, - x^2 , has to be
treated differently from the last one, - y^2 . (A principle at work
here is the one Rex Page pointed out: that we expect - <expression>
to be equivalent to 0 - <expression> .) This is a disaster waiting to
happen, in my opinion.
On the other hand, if we really do want to negate first and then
exponentiate, for example,
1/4
(-x)
we need the parentheses in ordinary mathematical notation, and expect
that we should need them in a program.
The designers of Fortran were striving to produce a programming
notation that closely resembles mathematical notation (and of course,
this is the origin of the name). They considered this issue, and
got it right. Most languages in the Algol tradition followed suit.
As Brian points out, there are exceptions: in particular, Algol 68
and C. But why did these languages break with tradition? I suspect
it is because these languages each have a plethora of prefix operators
without any obvious precedence, and furthermore, these operators
are allowed to pile up on one another; thus the only consistent thing
to do is make all prefix operators bind tightly. This strikes me
as an act of desperation, rather like APL's decision to have no
precedence at all and make all operators right-associative (for which
decision it has often been criticized).
Notice that with a single prefix operator, Haskell is more like Fortran
and Algol 60 than Algol 68 or C, so it is sensible to use the
traditional sort of operator syntax.
-Joe