[Haskell-cafe] Custom unary operator extension?

Malcolm Wallace Malcolm.Wallace at cs.york.ac.uk
Sun Sep 9 11:28:12 EDT 2007

> On Sun, 9 Sep 2007, Peter Verswyvelen wrote:
> > I find it unfortunate that one can't (I guess) define custom unary
> > operators in Haskell.

Incidentally, the nhc98 compiler has always permitted the definition of
unary operators, as an extension to the language.  (It was just more
convenient to create a general mechanism for unary/prefix operators,
than to code the special case for negative numbers.)

The definition syntax is rather like for infix decls:

    infixl 6  +
    prefix negate 6 -   -- WARNING Not standard Haskell

The operator symbol (-) is bound to a function name (negate), and has a
precedence just like infix operators.


More information about the Haskell-Cafe mailing list