| ... | @@ -39,11 +39,20 @@ |
... | @@ -39,11 +39,20 @@ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Resolve more prefix minus application unambiguously.
|
|
Resolve more prefix minus application unambiguously by:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1. Considering only operators to the right of prefix negation.
|
|
|
|
|
|
|
|
As described in [NegationBindsTightly](negation-binds-tightly) ghc rejects same terms
|
|
1. Leave prefix minus bind less tight than multiplication.
|
|
|
|
|
|
|
|
1. Do not consider associativity of prefix minus or (alternative formulation) let prefix minus bind a bit stronger than infix minus.
|
|
|
|
|
|
|
|
## Description
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
As described in [NegationBindsTightly](negation-binds-tightly) ghc rejects some terms
|
|
|
that are accepted by Hugs and Helium and should not be rejected in general.
|
|
that are accepted by Hugs and Helium and should not be rejected in general.
|
|
|
However, making negation bind more tightly is not the proposed solution here, because
|
|
However, making negation bind more tightly is not the proposed solution here, because
|
|
|
it would (in my eyes) wrongly resolve "`- x ^ 2`" to "`(-1) ^ 2`".
|
|
it would (in my eyes) wrongly resolve "`- x ^ 2`" to "`(-1) ^ 2`".
|
| ... | @@ -55,7 +64,9 @@ it would (in my eyes) wrongly resolve "`- x ^ 2`" to "`(-1) ^ 2`". |
... | @@ -55,7 +64,9 @@ it would (in my eyes) wrongly resolve "`- x ^ 2`" to "`(-1) ^ 2`". |
|
|
This condition ensures that "4 \* -5" is not rejected (as ghc does).
|
|
This condition ensures that "4 \* -5" is not rejected (as ghc does).
|
|
|
|
|
|
|
|
|
|
|
|
|
1. Prefix minus should bind less tight than multiplication but (slightly) stronger than addition and subtraction.
|
|
1. Prefix minus should bind less tight than multiplication but …
|
|
|
|
|
|
|
|
1. .. (slightly) stronger than addition and subtraction.
|
|
|
|
|
|
|
|
|
|
|
|
|
The latter condition ensures that "- x \# …" is resolved as "(- x) \# …" for any operator \# with lower precedence than multiplication.
|
|
The latter condition ensures that "- x \# …" is resolved as "(- x) \# …" for any operator \# with lower precedence than multiplication.
|
| ... | @@ -72,29 +83,44 @@ However, Hugs rejects "-4 \# 5" for a non-left-associative operator \# with prec |
... | @@ -72,29 +83,44 @@ However, Hugs rejects "-4 \# 5" for a non-left-associative operator \# with prec |
|
|
|
|
|
|
|
```wiki
|
|
```wiki
|
|
|
infix # 6
|
|
infix # 6
|
|
|
(#) = undefined
|
|
(#) = (-)
|
|
|
x7 = -4 # 5
|
|
x7 = - 4 # 5
|
|
|
x8 = 4 # -5
|
|
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
x7 and x8 should be accepted, too. They are currently rejected by Hugs and ghc.
|
|
x7 are currently rejected by Hugs and ghc. Two solutions are possible. Since "-" should just bind weaker than multiplication the possibility "-(4 \# 5)" cannot be justified, thus "(-4) \# 5" should be the unique solution.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Surely, one can always disallow "confusing" resolutions, but if we reject "- 4 \# 5", we can also reject "- 4 - 5" or "`- 4 ^ 5`".
|
|
|
|
Associativity seems wrong to consider for the unary minus function. (But it is an option to simple use the way of Hugs for ghc, too.)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
As an option it is possible to support multiple prefix minus application. ("4 \* - - 5" can be resolved in the same way as
|
|
As a further option it is possible to support multiple prefix minus application. ("4 \* - - 5" can be resolved in the same way as
|
|
|
"4 \* - 5" is).
|
|
"4 \* - 5" is).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## References
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
For other examples see
|
|
For other examples see
|
|
|
[ http://www.haskell.org/pipermail/haskell-prime/2010-July/003229.html](http://www.haskell.org/pipermail/haskell-prime/2010-July/003229.html)
|
|
[ http://www.haskell.org/pipermail/haskell-prime/2010-July/003229.html](http://www.haskell.org/pipermail/haskell-prime/2010-July/003229.html)
|
|
|
|
|
|
|
|
|
|
|
|
|
## Description
|
|
|
|
|
|
|
|
|
|
|
Mixfix analysis \[Aasa95\] usually only considers the top-level operators of argument terms.
|
|
|
|
This backs my point 1. above: Do not look to the left of prefix minus, because there is no argument of prefix minus.
|
|
|
|
|
|
|
|
## References
|
|
|
|
|
|
|
|
|
|
Also Isabelle ([ http://isabelle.in.tum.de/](http://isabelle.in.tum.de/)) allows prefix operators to have lower precedence than infix operators.
|
|
|
|
Other specification languages (like HasCASL) do so, too. For instance the logical prefix negation binds stronger than logical connectives but weaker than infix equality or other comparisons. (This does not apply to the "not" in Haskell, because "not" is a plain function, no operator).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
My point 3. is backed by the fact that "in case of doubt" prefix application should bind stronger than infix application.
|
|
|
|
|
|
|
|
|
|
|
|
|
## Report Delta
|
|
## Report Delta
|
| ... | | ... | |