Skip to content

Confusion related to the minus operator

Summary

The negation sign (-) appears to be parsed incorrectly in several situations, mostly while using infix operators, creating a confusing result.

The wiki states that The unary minus is syntactic sugar for the Prelude function negate., yet it appears that the precedence differs between the unary minus and the negation function.

Steps to reproduce

  1. Open ghci
  2. Evaluate the following expressions:
  • -1 `mod` 3
  • (-1) `mod` 3
  • negate 1 `mod` 3
  • -9 `div` 10
  • (-9) `div` 10
  • negate 9 `div` 10

Expected behavior

I expected the first and fourth expressions to evaluate just like their counterparts, with parantheses and negate respectively, yet it appears that the rest of the expression is evaluated, then negated, instead of the numbers being treated as negative numbers.

Environment

  • GHC version used:

Optional:

  • Operating System: NixOS unstable
  • System Architecture: x86_64

Any clarification would be helpful.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information