As a footnote to grddev's answer, here's the relevant paragraph from the Haskell 98 Report:
The special form -e
denotes prefix
negation, the only prefix operator in
Haskell, and is syntax for negate
(e)
. The binary -
operator does not
necessarily refer to the definition of
-
in the Prelude; it may be rebound by the module system. However, unary -
will always refer to the negate
function defined in the Prelude. There
is no link between the local meaning
of the -
operator and unary negation.
This is something that frustrated me when I first came across it: I couldn't understand why the operators behaved so differently in this context when :info (+)
and :info (-)
looked basically identical.
You could use subtract
, as grddev suggests, or you could just define a new infix operator:
Prelude> let (#) = (-)
Prelude> (# 3) 2
-1
subtract
has the advantage of being familiar to other people who might read your code.