Re: Definable operators (was: Problems with Hardware, Languages, and Compilers)

nmm1@cus.cam.ac.uk (Nick Maclaren)
16 Mar 1997 23:17:31 -0500

          From comp.compilers

Related articles
Problems with Hardware, Languages, and Compilers hrubin@stat.purdue.edu (1997-03-07)
Definable operators (was: Problems with Hardware, Languages, and Compi rrogers@cs.washington.edu (1997-03-09)
Re: Definable operators (was: Problems with Hardware, Languages, and C sethml@ugcs.caltech.edu (1997-03-13)
Re: Definable operators (was: Problems with Hardware, Languages, and C rrogers@cs.washington.edu (1997-03-13)
Re: Definable operators (was: Problems with Hardware, Languages, and C creedy@mitretek.org (1997-03-14)
Re: Definable operators (was: Problems with Hardware, Languages, and C nmm1@cus.cam.ac.uk (1997-03-16)
Re: Definable operators (was: Problems with Hardware, Languages, and C andy@cs.Stanford.EDU (1997-03-16)
Re: Definable operators (was: Problems with Hardware, Languages, and C malcolm@sedi8.nag.co.uk (1997-03-16)
Re: Definable operators (was: Problems with Hardware, Languages, and C apardon@rc4.vub.ac.be (1997-03-18)
Re: Definable operators (was: Problems with Hardware, Languages, and C jenglish@crl.com (1997-03-18)
Re: Definable operators (was: Problems with Hardware, Languages, and C nmm1@cus.cam.ac.uk (1997-03-21)
| List of all articles for this month |

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
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.