Re: [Haskell-cafe] Custom unary operator extension?
On Sun, 9 Sep 2007, Peter Verswyvelen wrote: Henning Thielemann wrote: The more syntactic constructs exist, the more complicated it becomes to read such programs. Today, if you read a symbolic operator which is not -, not a single dot with a capital identifier to the left (qualification), not a double dot in a bracket (enumeration) and not enclosed in parentheses (prefix mode), then it is an infix operator. Note the already existing exceptions, and I feel these are not complete. With prefix operators it becomes more difficult. Okay, so the choice was to enhance readability. Yes, something can be said for that, because in C++ and C#, operator overloading is a no-go in general, in those language, it is prefered to use clear and long function names. But as Haskell seemed more math-mind oriented, I was just wandering why unary operator support was missing. Since students will surely ask me why I can't create a symbolic operator for the not function, I now have a good answer ready ;-) I have read about APL that it uses a special character set in order to get a more mathematical looking notation. Maybe your students should check out this language? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] Custom unary operator extension?
Incidentally, GHC does allow postfix unary operators. http://www.haskell.org/ghc/docs/latest/html/users_guide/syntax-extns.html#postfix-operators Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Custom unary operator extension?
Nice. Thanks for the info, but the symbolic notation is not the only reason for using Haskell, it's also to force them into solving simple problems without using mutable variables, so they see this alternative functional programming approach BEFORE they are specialist in C++, because then they will be in the blob zone ;-) Maybe APL is also a functional language, but unfortunately I don't have the time to switch to another language anymore. Besides, I'm addicted to Haskell now ;-) Henning Thielemann: I have read about APL that it uses a special character set in order to get a more mathematical looking notation. Maybe your students should check out this language? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Custom unary operator extension?
APL is fairly obsolete now anyway. A more modern version of that language is J (www.jsoftware.com), which does not use special characters. I've studied the language a bit, and it's quite interesting, but it really doesn't offer much (anything?) over Haskell except a much terser notation and simpler mutable array support. I'd stick to Haskell. Mike Peter Verswyvelen wrote: Nice. Thanks for the info, but the symbolic notation is not the only reason for using Haskell, it's also to force them into solving simple problems without using mutable variables, so they see this alternative functional programming approach BEFORE they are specialist in C++, because then they will be in the blob zone ;-) Maybe APL is also a functional language, but unfortunately I don't have the time to switch to another language anymore. Besides, I'm addicted to Haskell now ;-) Henning Thielemann: I have read about APL that it uses a special character set in order to get a more mathematical looking notation. Maybe your students should check out this language? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Custom unary operator extension?
Thanks for the advice. Well, if I wanted to use a language with rich mathematical symbol support, I would use Sun's Fortress, which allows any unicode character. But that language is scheduled to be released by 2010, if it gets released. An interpreter is available though. But I'll stick to Haskell ;-) Michael Vanier wrote: APL is fairly obsolete now anyway. A more modern version of that language is J (www.jsoftware.com), which does not use special characters. I've studied the language a bit, and it's quite interesting, but it really doesn't offer much (anything?) over Haskell except a much terser notation and simpler mutable array support. I'd stick to Haskell. Mike Peter Verswyvelen wrote: Nice. Thanks for the info, but the symbolic notation is not the only reason for using Haskell, it's also to force them into solving simple problems without using mutable variables, so they see this alternative functional programming approach BEFORE they are specialist in C++, because then they will be in the blob zone ;-) Maybe APL is also a functional language, but unfortunately I don't have the time to switch to another language anymore. Besides, I'm addicted to Haskell now ;-) Henning Thielemann: I have read about APL that it uses a special character set in order to get a more mathematical looking notation. Maybe your students should check out this language? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Custom unary operator extension?
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. http://www.haskell.org/pipermail/haskell-cafe/2006-September/017941.html I think that the benefits of prefix or postfix symbolic operators were not worth dispensing with the comfortable section syntax. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Custom unary operator extension?
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 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Custom unary operator extension?
On Sep 9, 2007, at 9:09 , Peter Verswyvelen wrote: 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 ;-) I think I'd prefer _ instead of ? there, because it already has the meaning of placeholder. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED] system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED] electrical and computer engineering, carnegie mellon universityKF8NH ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Custom unary operator extension?
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. Regards, Malcolm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Custom unary operator extension?
On Sun, 2007-09-09 at 15:09 +0200, Peter Verswyvelen wrote: 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 ;-) With enough insanity simulating infix operators should be no problem, http://www.informatik.uni-bonn.de/~ralf/publications/Quote.pdf ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Custom unary operator extension?
Brandon S. Allbery KF8NH wrote: On Sep 9, 2007, at 9:09 , Peter Verswyvelen wrote: 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 ;-) I think I'd prefer _ instead of ? there, because it already has the meaning of placeholder. Indeed, much better! Peter ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Custom unary operator extension?
Malcolm Wallace wrote: 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.) Cool! I found it rather ugly that the negation operator was wired-in. It's a petty this is not part of the upcoming Haskell standard, or is it? GHC can't do this right? Peter ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Custom unary operator extension?
On Sun, 9 Sep 2007, Peter Verswyvelen wrote: 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#. The more syntactic constructs exist, the more complicated it becomes to read such programs. Today, if you read a symbolic operator which is not -, not a single dot with a capital identifier to the left (qualification), not a double dot in a bracket (enumeration) and not enclosed in parentheses (prefix mode), then it is an infix operator. Note the already existing exceptions, and I feel these are not complete. With prefix operators it becomes more difficult. 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 :-) Even more simpler is enclosing the symbolic operator in parentheses. (-|) :: Bool - Bool use as(-|) False 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 ;-) It's easy to predict, that people then soon want to write (? * ?), disputing whether it shall mean (\x - x*x) or (\x y - x*y), and you will quickly re-invent lambda notation. See http://www.haskell.org/pipermail/haskell-cafe/2006-July/016683.html It's tempting to want more syntactic sugar, but there are already so much suggestions that I'm afraid, that the resulting language would be as ambiguous as a natural language. http://www.haskell.org/haskellwiki/Syntactic_sugar/Cons ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Custom unary operator extension?
Henning Thielemann wrote: The more syntactic constructs exist, the more complicated it becomes to read such programs. Today, if you read a symbolic operator which is not -, not a single dot with a capital identifier to the left (qualification), not a double dot in a bracket (enumeration) and not enclosed in parentheses (prefix mode), then it is an infix operator. Note the already existing exceptions, and I feel these are not complete. With prefix operators it becomes more difficult. Okay, so the choice was to enhance readability. Yes, something can be said for that, because in C++ and C#, operator overloading is a no-go in general, in those language, it is prefered to use clear and long function names. But as Haskell seemed more math-mind oriented, I was just wandering why unary operator support was missing. Since students will surely ask me why I can't create a symbolic operator for the not function, I now have a good answer ready ;-) Thanks, Peter ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe