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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 175D5BBAF for ; Wed, 10 Nov 2010 14:44:33 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgoBAG8w2kxV6aAZmGdsb2JhbACDOpBJjjMVAQECAQgJDAcRIqwzkHmBIoM1cwSKV4MMgm4 X-IronPort-AV: E=Sophos;i="4.59,178,1288566000"; d="scan'208";a="86699281" Received: from outgoing-smtp.namesco.net ([85.233.160.25]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 10 Nov 2010 14:44:32 +0100 Received: from [192.168.0.8] (helo=arion.hosts.co.uk) by outgoing-smtp.namesco.net with esmtp (Exim 4.67) (envelope-from ) id 1PGAyR-0000ko-7u; Wed, 10 Nov 2010 13:44:29 +0000 Received: from root by arion.hosts.co.uk with local (Exim 4.69) (envelope-from ) id 1PGAyS-0006wd-3H; Wed, 10 Nov 2010 13:44:28 +0000 To: , , Cc: From: Reply-To: Subject: =?utf-8?q?Re=3a=20=5bCaml=2dlist=5d=20Infix=20function=20composition=20operator?= MIME-Version: 1.0 X-Mailer: Namesco Webmail v3.0 Message-ID: <1289396667803@names.co.uk> Date: Wed, 10 Nov 2010 13:44:27 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-namescosender: 0 2002 X-namesco: 192.168.0.171 X-Spam-Score: -1.0 (-) X-Spam: no; 0.00; infix:01 ocaml's:01 ocaml:01 cheers:01 yminsky:01 infix:01 yminsky:01 ocaml:01 beginner's:01 bug:01 bounces:98 arlen:98 beginners:01 wrote:01 wrote:01 So how does value restriction affect things here? (excuse my lack of knowledge) One thing about using a pipeline like this is that it relies on '|>' being left-associative (which it is due to OCaml's convention on operators that start with "|"). Mark. on 10/11/10 12:52 PM, Jon Harrop wrote: > A pipeline operator is usually preferred over function composition in impure > languages like OCaml and F# due to the value restriction. For example, your > example would be written in F# as: > > x |> op1 |> op2 |> op3 |> op4 |> op5 > > This style is very common in F#, particularly when dealing with collections. > > Cheers, > Jon. > >> -----Original Message----- >> From: caml-list-bounces@yquem.inria.fr [mailto:caml-list- >> bounces@yquem.inria.fr] On Behalf Of mark@proof-technologies.com >> Sent: 10 November 2010 07:00 >> To: yminsky@gmail.com; arlen@noblesamurai.com >> Cc: caml-list@inria.fr >> Subject: Re: [Caml-list] Infix function composition operator >> >> on 10/11/10 3:45 AM, yminsky@gmail.com 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 agree that using a composition operator can make the code obtuse, and >> so >> should not be overused. But it's incredibly useful for certain >> situations: >> >> 1) If you are performing a long chain of composed operations, it avoids >> nested bracketing piling up. >> >> For example: >> (op5 <<- op4 <<- op3 <<- op2 <<- op1) x >> Instead of: >> op5 (op4 (op3 (op2 (op1 x)))) >> >> This sort of thing happens quite a lot in certain applications, e.g. in >> language processing, to get at subexpressions. >> >> 2) Creating an anonymous function to be passed as an argument, it >> avoids >> explicitly mentioning arguments of that function. >> >> This sort of thing can happen a lot in functional programming >> generally. >> >> For example: >> List.map (op2 <<- op1) xs >> Instead of: >> List.map (fun x -> op2 (op1 x)) xs >> >> Mark Adams >> >> _______________________________________________ >> 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 > > > >