From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 10CABBCAB for ; Fri, 27 May 2005 14:46:16 +0200 (CEST) Received: from smtp.irisa.fr (smtp.irisa.fr [131.254.254.26]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j4RCkFEc004773 for ; Fri, 27 May 2005 14:46:15 +0200 Received: from localhost (localhost.localdomain [127.0.0.1]) by localhost.irisa.fr (Postfix) with ESMTP id A82F7FAC5; Fri, 27 May 2005 14:46:15 +0200 (CEST) Received: from smtp.irisa.fr ([131.254.254.26]) by localhost (meli.irisa.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 11311-01; Fri, 27 May 2005 14:46:11 +0200 (CEST) Received: from mail.irisa.fr (melo.irisa.fr [131.254.254.28]) by smtp.irisa.fr (Postfix) with ESMTP id B3E52FAA2; Fri, 27 May 2005 14:46:11 +0200 (CEST) Received: from 131.254.50.45 (SquirrelMail authenticated user padiolea) by mail.irisa.fr with HTTP; Fri, 27 May 2005 14:46:11 +0200 (CEST) Message-ID: <33823.131.254.50.45.1117197971.squirrel@mail.irisa.fr> In-Reply-To: <20050527105824.GA6650@furbychan.cocan.org> References: <20050527105824.GA6650@furbychan.cocan.org> Date: Fri, 27 May 2005 14:46:11 +0200 (CEST) Subject: Re: [Caml-list] infix functions From: padiolea@irisa.fr To: "Richard Jones" Cc: "Jonathan Roewen" , caml-list@yquem.inria.fr User-Agent: SquirrelMail/1.4.4 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal X-Virus-Scanned: by amavisd-new at irisa.fr X-Miltered: at concorde with ID 42971697.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 infix:01 irisa:01 infix:01 ens-lyon:01 haskell:01 ogi:01 pcaml:01 expr:01 expr:01 notation:01 ...:98 wrote:01 arbitrary:01 simpler:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.2 required=5.0 tests=NO_REAL_NAME autolearn=disabled version=3.0.2 X-Spam-Level: > On Fri, May 27, 2005 at 10:06:10PM +1200, Jonathan Roewen wrote: >> Hi, >> >> I see some pervasive functions are infix, and I'm wondering if there's >> any plan to support making any arbitrary infix functions? >> >> For instance, the Int32 (etc) modules are horrible to use cause of the >> prefix functions. These are perfect candidates for being infix. And >> being an OS project, Can we access the code of this OS project ? I know that there is another OS project with caml called funk at http://perso.ens-lyon.fr/samuel.mimram/docs/funk_doc/ and another one called House but with haskell http://www.cse.ogi.edu/~hallgren/House/ that you might be interested in. > It's also possible to create infix functions; however you have to use > the camlp4 preprocessor and your functions become reserved words in > the language. Here is an example of an infix function which should > get you started: > > open Pcaml > > EXTEND > expr: AFTER "apply" > [ LEFTA > [ e1 = expr; "map_with"; e2 = expr -> > <:expr< List.map $e2$ $e1$ >> > ] > ]; > END > > So using that extension you could write code like: > > list map_with (fun elem -> ...) I think it is simpler for such cases to have a generic operator such as let (+>) o f = f o and then just do [1;2;3;4] +> map (fun x -> x+1) which is reminescent of object notation.