Fixity was: Negation
Christian Maeder
Christian.Maeder at dfki.de
Sun Feb 14 09:25:55 EST 2010
S. Doaitse Swierstra schrieb:
> weird :: Int -> Int
> weird = (if True then 3 else 5+)
>
> is perfectly correct Haskell?
Yes, this is legal according to the grammar
http://haskell.org/onlinereport/syntax-iso.html
but rejected by ghc and hugs, because "5+" is illegal.
The problem is to allow let-, if-, do-, and lambda-expressions
to the left of operators (qop), because for those the meta rule
"extend as far as possible" should apply.
Switching to the new grammar
http://hackage.haskell.org/trac/haskell-prime/wiki/FixityResolution
infixexp -> exp10 qop infixexp
| - infixexp
| exp10
should be replaced by:
infixexp -> fexp qop infixexp
| exp10
(omitting the negate rule)
or shorter: "infixexp -> { fexp qop } exp10"
Left sections should look like:
( {fexp qop} fexp qop )
It would be even possible to avoid parenthesis around sections, because
a leading or trailing operator (or just a single operator) uniquely
determines the kind of expression.
Negation should be added independently to fexp (and possibly to exp10, too)
fexp -> [fexp] aexp (function application)
minusexp -> fexp | - fexp
infixexp -> minusexp qop infixexp
| exp10
| - exp10
(unless some wants the old FORTRAN behaviour of unary "-" to bind weaker
than infix multiplication and exponentiation.)
Cheers Christian
More information about the Haskell-prime
mailing list