[Haskell-cafe] Custom unary operator extension?
lemming at henning-thielemann.de
Sun Sep 9 06:27:50 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.
Why? What is your application? In fact, alphanumeric identifiers are used
as unary operators.
> Is this correct? If so, is this just because eg (* 100) declares a function
> that partially applies the * operator, so this syntax disallows unary
> operators? Could this be fixed by introducing a different syntax for partial
> operator application? E.g. (? * 100) instead of just (*100)?
You can also use "special syntax" for having unary operators. E.g.
(*) :: () -> a -> a
used as ()*100 :-)
> This would also fix the ambiguity between (-10) as being either the
> number minus 10 or the "subtract by 10' function.
There has been a long discussion whether the unary minus belongs to number
literals or not.
I think that the benefits of prefix or postfix symbolic operators were not
worth dispensing with the comfortable section syntax.
More information about the Haskell-Cafe