[Haskell-cafe] Custom unary operator extension?

Peter Verswyvelen bf3 at telenet.be
Sun Sep 9 09:09:00 EDT 2007


> Why? What is your application? In fact, alphanumeric identifiers are 
> used as unary operators.
Why? Well, why are binary operators allowed and unary operators not? 
Isn't that some kind of discrimination? In math, many many operators are 
unary. Haskell allows creating binary operators. So I would understand 
that Haskell supported neither binary nor unary operators, but prefering 
one above the other just seems odd. Especially when coming from C++ and C#.

My application? I'm teaching basic math to beginning video game 
programmers, and I wanted to demonstrate the logic operators "not, and, 
or, logical equivalence and implication" etc in Haskell, building them 
from scratch. Since most programmers have symbol-phobia, I wanted to let 
them play with the symbols for operators, with Haskell. E.g. \/, /\,  
--> <--> ==> <==> for or, and, if/then, iff, logical implication, 
logical equivalence, etc... I cannot do this for the "not" operator, 
which is a bit annoying, but it's not a show stopper.

> You can also use "special syntax" for having unary operators. E.g.
>
> (*) :: () -> a -> a
>
Nice trick :-)

> There has been a long discussion whether the unary minus belongs to 
> number literals or not.
>  http://www.haskell.org/pipermail/haskell-cafe/2006-September/017941.html

Yes I read it...

> I think that the benefits of prefix or postfix symbolic operators were 
> not worth dispensing with the comfortable section syntax.
Well, that's personal I guess, but I would prefer the syntax (? / 100) 
and (100 / ?), which is just a single extra character to type, and hence 
allow unary operators, but hey, that's just me, the newbie ;-)

Thanks,
Peter



More information about the Haskell-Cafe mailing list