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 VAA01491; Sat, 14 Aug 2004 21:52:26 +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 VAA02634 for ; Sat, 14 Aug 2004 21:52:25 +0200 (MET DST) Received: from relaissmtp.ens-lyon.fr (pluvier.ens-lyon.fr [140.77.167.5]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i7EJqORM005854 for ; Sat, 14 Aug 2004 21:52:24 +0200 Received: from mouette.ens-lyon.fr ([140.77.167.4]) by relaissmtp.ens-lyon.fr with esmtp (Exim 3.35 #1 (Debian)) id 1Bw4Zk-0008Vv-00 for ; Sat, 14 Aug 2004 21:52:24 +0200 Received: by mouette.ens-lyon.fr (Postfix, from userid 33) id E17063C61C2; Sat, 14 Aug 2004 21:52:23 +0200 (CEST) To: caml-list@inria.fr Subject: Re: [Caml-list] Infix operators Message-ID: <1092513143.411e6d777adcb@mouette.ens-lyon.fr> Date: Sat, 14 Aug 2004 21:52:23 +0200 (CEST) From: Jean-Baptiste Rouquier References: <20040814225919.0bed9f65.ocaml-erikd@mega-nerd.com> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit User-Agent: IMP/PHP IMAP webmail program 2.2.6 X-Originating-IP: 68.40.185.95 X-Miltered: at concorde with ID 411E6D78.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 ens-lyon:01 rubbish:01 stdin:01 stdin:01 infix:03 infix:03 12.:95 let:04 let:04 define:05 define:05 i'd:06 lexer:09 lexer:09 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk >>I'd like to define [many] infix operators >I came up with a totally rubbish solution to this: define an "infix-ising" >operator like so which lets you use "long" operator names made of plain >characters: > > let (%) a b = b a > > let add a b = a + b > let addf a b = a +. b > > 5 %add 6 > 10. %addf 12. I sometimes use it as a "pipe" operator : let (|>) x f = f x let () = input_line stdin |> lexer |> parser' |> computation |> pretty_print instead of let input = input_line stdin in let temp = lexer input in let temp = parser' temp in let temp = computation temp in pretty_print temp;; -- Jean-Baptiste Rouquier ------------------- 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