>[.... I used IMP72, a language where>you could add any operations you wanted, and it was awful. -John]>
Richard Rogers <rrogers@cs.washington.edu> wrote:>But I've never used a language that allowed operator definition....

sethml@ugcs.caltech.edu (Seth LaForge) writes:
|> Try Haskell. Besides being a side-effect-free lazy evaluation language,
|> Haskell has a lot of syntactic sugar. In particular, you can define
|> pretty much arbitrary operators. Any token which consists entirely of
|> operator characters (+-*/%<>= and a few others) is considered an infix
|> operator by the parser. You also set the associativity and precedence:
|>
|> -- Declare <<< to be a precedence 7 left-associative operator:
|> infixl 7 <<<
|> -- Type declaration: <<< takes two integers and returns an
|> -- integral number of the type of the first argument:
|> (<<<) :: (Integral a, Integral b) => a -> b -> a
|> -- The actual function: left bit shift:
|> x <<< b = x * 2^b

Algol 68 did, and was by no means the first. But Haskell has made a
very old mistake in being too general - consider the problems about
parsing a mixture of left- and right-associative operators of the same
priority. Even worse, consider varying commutativity and
distributivity. The 1960s experience was that allowing user- defined
operators (including redefinition) was fine, as was allowing
user-defined precedences for textually new ones, but beyond that lies
madness.