Personal tools

Unary operator

From HaskellWiki

Revision as of 10:37, 9 September 2007 by Lemming (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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
. The unary minus is syntactic sugar for the Prelude function

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