wiki:PrefixMinusResolution

Version 1 (modified by maeder, 4 years ago) (diff)

first description

Proposal: PrefixMinusResolution

Ticket
Dependencies
Related FixityResolution NegativeSyntax NegationBindsTightly

Compiler support

GHC [ none ]
nhc98 [ none ]
Hugs [ partial ]
UHC [ unknown ]
JHC [ none ]
LHC [ unknown ]

Summary

Resolve more prefix minus application unambiguously.

As described in NegationBindsTightly 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.

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

Description

References

Report Delta