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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id DA500BBAF for ; Wed, 10 Nov 2010 13:52:19 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjgBAD4k2kxKfVK2kGdsb2JhbACDOpBJgVSMVwgVAQECCQkMBxEDH6JqiSSCVAEFjh4BBIEigzVzkFU X-IronPort-AV: E=Sophos;i="4.59,177,1288566000"; d="scan'208";a="65398734" Received: from mail-wy0-f182.google.com ([74.125.82.182]) by mail3-smtp-sop.national.inria.fr with ESMTP; 10 Nov 2010 13:52:19 +0100 Received: by wya21 with SMTP id 21so686752wya.27 for ; Wed, 10 Nov 2010 04:52:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:references :in-reply-to:subject:date:organization:message-id:mime-version :content-type:content-transfer-encoding:x-mailer:thread-index :content-language; bh=Odxjdf1CwuG9jAuxwJ/MUL1KQmPdQ5LQEe8c4DKngwk=; b=hUX3DBd4ny/AppsD4xzKgoI+AG1CisL/HML+QQbM0V5yguR+vRhiDjks3dfYOpUDm8 9marEjdTCvOknei+oUyRH1HrmcWYM5JlIHLBYLL47ITBh+J4DzxXslBg3sp7wIs7gVbb cXiffiFZriL3hk2tWGZA4mn4/Zzihw2wwr/VE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=from:to:cc:references:in-reply-to:subject:date:organization :message-id:mime-version:content-type:content-transfer-encoding :x-mailer:thread-index:content-language; b=e3P7/wZZoxU2Y78qFpSFNgDOm5m/6u89gvMrtxx549bqttJ+t0OJcdpSdSMHxckD9I Bs4KiFS57eWAWc9SDjH0SKdSU1O3F7UoKh1IAMdOzeGQsOycrxsxR4rptxeWypBmTG6X /NgtQe6iQaGvHmtr+DouLcjQVmtpeOxY8HT/w= Received: by 10.227.155.11 with SMTP id q11mr8215842wbw.130.1289393538470; Wed, 10 Nov 2010 04:52:18 -0800 (PST) Received: from WinEight ([87.112.186.137]) by mx.google.com with ESMTPS id b30sm565895wbb.22.2010.11.10.04.52.15 (version=SSLv3 cipher=RC4-MD5); Wed, 10 Nov 2010 04:52:16 -0800 (PST) From: Jon Harrop To: , , Cc: References: <1289372378510@names.co.uk> In-Reply-To: <1289372378510@names.co.uk> Subject: RE: [Caml-list] Infix function composition operator Date: Wed, 10 Nov 2010 12:51:54 -0000 Organization: Flying Frog Consultancy Message-ID: <020e01cb80d6$0e52b890$2af829b0$@com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AcuApPX6o5lKQ2noTU+LdXToPwK3NgAMII1w Content-Language: en-gb X-Spam: no; 0.00; infix: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 avoids:01 avoids:01 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 >=20 > on 10/11/10 3:45 AM, yminsky@gmail.com wrote: >=20 > > 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. >=20 > 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: >=20 > 1) If you are performing a long chain of composed operations, it = avoids > nested bracketing piling up. >=20 > For example: > (op5 <<- op4 <<- op3 <<- op2 <<- op1) x > Instead of: > op5 (op4 (op3 (op2 (op1 x)))) >=20 > This sort of thing happens quite a lot in certain applications, e.g. = in > language processing, to get at subexpressions. >=20 > 2) Creating an anonymous function to be passed as an argument, it > avoids > explicitly mentioning arguments of that function. >=20 > This sort of thing can happen a lot in functional programming > generally. >=20 > For example: > List.map (op2 <<- op1) xs > Instead of: > List.map (fun x -> op2 (op1 x)) xs >=20 > Mark Adams >=20 > _______________________________________________ > 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