|
|
|
# Proposal: [PrefixMinusResolution](prefix-minus-resolution)
|
|
|
|
|
|
|
|
<table><tr><th> Ticket </th>
|
|
|
|
<th></th></tr>
|
|
|
|
<tr><th> Dependencies </th>
|
|
|
|
<th></th></tr>
|
|
|
|
<tr><th> Related </th>
|
|
|
|
<th>[FixityResolution](fixity-resolution)[NegativeSyntax](negative-syntax)[NegationBindsTightly](negation-binds-tightly)</th></tr></table>
|
|
|
|
|
|
|
|
## Compiler support
|
|
|
|
|
|
|
|
<table><tr><th> GHC </th>
|
|
|
|
<th> \[ none \]
|
|
|
|
</th></tr>
|
|
|
|
<tr><th> nhc98 </th>
|
|
|
|
<th> \[ none \]
|
|
|
|
</th></tr>
|
|
|
|
<tr><th> Hugs </th>
|
|
|
|
<th> \[ partial \]
|
|
|
|
</th></tr>
|
|
|
|
<tr><th> UHC </th>
|
|
|
|
<th> \[ unknown \]
|
|
|
|
</th></tr>
|
|
|
|
<tr><th> JHC </th>
|
|
|
|
<th> \[ none \]
|
|
|
|
</th></tr>
|
|
|
|
<tr><th> LHC </th>
|
|
|
|
<th> \[ unknown \]
|
|
|
|
</th></tr></table>
|
|
|
|
|
|
|
|
## Summary
|
|
|
|
|
|
|
|
|
|
|
|
Resolve more prefix minus application unambiguously.
|
|
|
|
|
|
|
|
|
|
|
|
As described in [NegationBindsTightly](negation-binds-tightly) ghc rejects same terms
|
|
|
|
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
|
|
|
|
it would (in my eyes) wrongly resolve "`- x ^ 2`" to "`(-1) ^ 2`".
|
|
|
|
|
|
|
|
1. Only operators to the right of prefix negation need to be considered for resolution.
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
The latter condition ensures that "- x \# …" is resolved as "(- x) \# …" for any operator \# with lower precedence than multiplication.
|
|
|
|
|
|
|
|
|
|
|
|
"-4 \* 5" will be resolved to "-(4 \* 5)" as Hugs correctly does already.
|
|
|
|
I don't know how Helium resolves this, but it does (usually) not matter for multiplication if it were resolved to "(-4) \* 5".
|
|
|
|
|
|
|
|
|
|
|
|
However, Hugs rejects "-4 \# 5" for a non-left-associative operator \# with precedence 6, because it compares associativities for operators with the same precedence. Therefore prefix minus should have a (slightly) higher precedence than infix operators with the precedence of infix minus.
|
|
|
|
|
|
|
|
```wiki
|
|
|
|
infix # 6
|
|
|
|
(#) = undefined
|
|
|
|
x7 = -4 # 5
|
|
|
|
x8 = 4 # -5
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
x7 and x8 should be accepted, too. They are currently rejected by Hugs and ghc.
|
|
|
|
|
|
|
|
|
|
|
|
As an option it is possible to support multiple prefix minus application. ("4 \* - - 5" can be resolved in the same way as
|
|
|
|
"4 \* - 5" is).
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
## Description
|
|
|
|
|
|
|
|
## References
|
|
|
|
|
|
|
|
## Report Delta |
|
|
\ No newline at end of file |