From: | nmm1@cus.cam.ac.uk (Nick Maclaren) |
Newsgroups: | comp.compilers,comp.lang.misc,comp.arch.arithmetic |
Date: | 16 Mar 1997 23:17:31 -0500 |
Organization: | University of Cambridge, England |
References: | 97-03-037 97-03-043 97-03-047 |
Keywords: | design |
>[.... 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.
Nick Maclaren,
University of Cambridge Computer Laboratory,
New Museums Site, Pembroke Street, Cambridge CB2 3QG, England.
Email: nmm1@cam.ac.uk
Tel.: +44 1223 334761 Fax: +44 1223 334679
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.