Personal tools

Unary operator

From HaskellWiki

(Redirected from Unary minus)
Jump to: navigation, search

A unary operator is an operator with one parameter. It can be written in prefix notation like in − 2 or in postfix notation 2! (factorial).

In Haskell there is only one unary operator, namely the unary minus. It has been discussed in length, whether the unary minus shall be part of numeric literals or whether it shall be an independent operator.

In fact in Haskell it is the latter one, in order to allow expressions like
-a
. The unary minus is syntactic sugar for the Prelude function
negate
.

The special syntax disallows the use of sectioning.

That is, you cannot write
map (-2)
if you want to substract 2 from all elements of a list. Instead you have to write
map (subtract 2)
.

See also