From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id JAA23857 for caml-red; Sat, 3 Jun 2000 09:30:15 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA11327 for ; Wed, 31 May 2000 18:45:45 +0200 (MET DST) Received: from shell5.ba.best.com (shell5.ba.best.com [206.184.139.136]) by concorde.inria.fr (8.10.0/8.10.0) with ESMTP id e4VGjiT26556 for ; Wed, 31 May 2000 18:45:44 +0200 (MET DST) Received: from localhost (bpr@localhost) by shell5.ba.best.com (8.9.3/8.9.2/best.sh) with ESMTP id JAA16532; Wed, 31 May 2000 09:45:39 -0700 (PDT) Date: Wed, 31 May 2000 09:45:39 -0700 (PDT) From: Brian Rogoff To: Steve Stevenson cc: caml-list@inria.fr Subject: Re: How do you declare infix in Ocaml In-Reply-To: <14643.48479.50162.753370@merlin.cs.clemson.edu> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: weis If you take a look at, for instance, the Num library, or the types of the infixes in Pervasives, you'll notice that the infix is parenthesized. That is also how you declare new ones, or redefine the existing ones. For example, # let (+@) x y = x + y - 1;; val ( +@ ) : int -> int -> int = # 1 +@ 0;; - : int = 0 and the new (+@) gets its precedence from the first character of the lexeme, the "+". Prefixes are defined similarly, # let (~@) = fun x -> String.uppercase x ;; val ( ~@ ) : string -> string = # ~@ "hi there";; - : string = "HI THERE" You can also redefine the existing infixes and prefixes, including the ones like mod, not, and or, but that would be very nasty. I wish that there was some mechanism like in Haskell to make infixes out of identifiers, but of course we would be back to having directives again to resolve ambiguities in precedence and associativity if this were the case. Camlp4 helps here. -- Brian On Tue, 30 May 2000, Steve Stevenson wrote: > In caml there are directives to do this. The obvious doesn't work in > Ocaml. > > best regards > > steve > >