Skip to content

Can't mix infix operator with prefix - using -XLexicalNegation

Summary

Given the description of proposal 229, and especially the sentence "Under -XLexicalNegation, prefix - binds tighter than any infix operator, so that -a % b is parsed as (-a) % b regardless of the fixity of %", I would expect a % -b to be parsed as a % (-b).

However, let a = 4; b = 6 in a % -b results in

<interactive>:9:21: error:
    Precedence parsing error
        cannot mix `%' [infixl 7] and prefix `-' [infixl 6] in the same infix expression

Steps to reproduce

In GHCi, enter :seti -XLexicalNegation, import Data.Ratio, and then let a = 4; b = 6 in a % -b.

Expected behavior

Parse a % -b as a % (-b), resulting in (-2) % 3.

Environment

  • GHC version used: 9.3.20210506

Optional:

  • Operating System: Arch in WSL2 on Windows 10
  • System Architecture: x64
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information