From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA02734; Fri, 23 Jul 2004 16:36:53 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 QAA02699 for ; Fri, 23 Jul 2004 16:36:52 +0200 (MET DST) Received: from annexia.force9.co.uk (annexia.force9.co.uk [212.56.101.183]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i6NEapSH007740 for ; Fri, 23 Jul 2004 16:36:51 +0200 Received: from rich by annexia.force9.co.uk with local (Exim 3.36 #1 (Debian)) id 1Bo1AJ-0003FT-00 for ; Fri, 23 Jul 2004 15:36:51 +0100 Date: Fri, 23 Jul 2004 15:36:51 +0100 Cc: caml-list@inria.fr Subject: Re: [Caml-list] Associativity precedence for the user-defined operator. Message-ID: <20040723143651.GA12453@redhat.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.5.1+cvs20040105i From: Richard Jones X-Miltered: at concorde with ID 41012283.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 2004:99 trento:99 sometype:01 camlp:01 camlp:01 pcaml:01 expr:01 expr:01 autoconf:01 automake:01 compiles:01 rpms:01 ltd:98 0200,:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Fri, Jul 23, 2004 at 04:27:06PM +0200, Claudio Trento wrote: > > Hi, > > I've defined a set of new operetors, for instance: > > let ( /+/ ) = add_num (where add_num is a function that added two sometype > elements.) > > but I don't know if I can set associativity precedence for this operator, > writing: el1 ( /+/ ) el2 ( /+/ ) el3 without parenthesis, what happens? The easiest way to control associativity and precedence seems to be to write a Camlp4 extension. For example here is a Camlp4 extension I wrote to create some left-associative ('LEFTA') ops: open Pcaml EXTEND expr: AFTER "apply" [ LEFTA [ e1 = expr; "map_with"; e2 = expr -> <:expr< List.map $e2$ $e1$ >> | e1 = expr; "iter_with"; e2 = expr -> <:expr< List.iter $e2$ $e1$ >> | e1 = expr; "filter_with"; e2 = expr -> <:expr< List.filter $e2$ $e1$ >> | e1 = expr; "concat_with"; e2 = expr -> <:expr< List.concat (List.map $e2$ $e1$) >> | e1 = expr; "apply_with"; e2 = expr -> <:expr< $e2$ $e1$ >> ] ]; END Rich. -- Richard Jones. http://www.annexia.org/ http://www.j-london.com/ Merjis Ltd. http://www.merjis.com/ - improving website return on investment MAKE+ is a sane replacement for GNU autoconf/automake. One script compiles, RPMs, pkgs etc. Linux, BSD, Solaris. http://www.annexia.org/freeware/makeplus/ ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners