From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 00AB2BBAF for ; Wed, 10 Nov 2010 05:37:42 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqoFADqw2Uyt/9A2/2dsb2JhbACDOZBPMY4CcapHkGiBIoM1cwSNYg X-IronPort-AV: E=Sophos;i="4.59,176,1288566000"; d="scan'208";a="77570647" Received: from sairyx.org ([173.255.208.54]) by mail4-smtp-sop.national.inria.fr with ESMTP; 10 Nov 2010 05:37:42 +0100 Received: by sairyx.org (Postfix, from userid 5001) id E1DDE48003; Wed, 10 Nov 2010 04:37:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on sairyx.org X-Spam-Level: Received: from [192.168.200.106] (203-206-182-151.perm.iinet.net.au [203.206.182.151]) (Authenticated sender: celtic@sairyx.org) by sairyx.org (Postfix) with ESMTPSA id DF60048001; Wed, 10 Nov 2010 04:37:37 +0000 (UTC) Subject: Re: [Caml-list] Infix function composition operator From: Arlen Christian Mart Cuss To: yminsky@gmail.com Cc: caml-list@inria.fr In-Reply-To: References: <1289359172.2282.15.camel@azayaka> Content-Type: text/plain; charset="UTF-8" Date: Wed, 10 Nov 2010 15:37:32 +1100 Message-ID: <1289363852.2282.25.camel@azayaka> Mime-Version: 1.0 X-Mailer: Evolution 2.30.3 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; infix:01 yaron:01 yaron:01 minsky:01 ocaml:01 lambda:01 struct:01 regexp:01 infix:01 cheers:01 ocaml:01 beginner's:01 bug:01 beginner's:01 bug:01 Hi Yaron, On Tue, 2010-11-09 at 22:45 -0500, Yaron Minsky wrote: > This is probably a minority opinion, but I have written and read quite > a lot of OCaml code over the years, and I've seen surprisingly few > effective uses of the composition operator. Somehow, I usually find > that code that avoids it is simpler and easier to read. I know what you mean - it can make some code more obtuse than just doing the same thing with a lambda. But I can't help but get the feeling it has a place here: (note: example is semi-contrived and there are plenty of better ways to do this, but just as an example) module CGI = struct (* ... *) let escape = let replace = Str.global_replace <<- Str.regexp_string in (replace "\"" """) <<- (replace "'" "'") <<- (replace "&" "&") Particularly the second line of `escape', where the escaping mechanism is indeed a composition of the three replaces as specified. Comparing that to this: let escape s = let replace = (* ... *) in replace "\"" """ (replace "'" "'" (replace "&" "&" s)) .. I prefer the former, as the latter forces me to specify an argument, and nest the calls to replace. I'm not sure if there are any performance benefits/losses as a result of computing the function `escape' in the first example, either, but it's a consideration. > I'm not averse to infix operators. At Jane Street we've found the > following sequencing operator to be highly useful: > > let ( |! ) x f = f x > > and it is indeed part of the default include in Jane Street's Core > library. That looks neat, and I imagine it to be useful, but I can't think of a concrete use-case off the cuff. Could you give an example? > y Cheers, Arlen > On Tue, Nov 9, 2010 at 10:19 PM, Arlen Christian Mart Cuss > wrote: > Hi all, > > I know this was asked at least 12 years ago[1], but is there > any > consensus or reason for there not being a "compose" function > in standard > OCaml, nor an infix operator? > > At the moment I tend to "let compose" or "let (<<-) f g x = f > (g x)", > but I wish I didn't have to! > > Thanks, > Arlen > > [1] > http://webcache.googleusercontent.com/search?q=cache:TcqI7o37il8J:pauillac.inria.fr/caml/caml-list/0720.html+ocaml+function+compose&cd=2&hl=en&ct=clnk&client=ubuntu > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs