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 00F25BBAF for ; Wed, 10 Nov 2010 07:59:58 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvoAADfS2UxV6aAZmGdsb2JhbACDOJ8CFQEBAQEBCAkMBxEiqk+QYoEigzVzBIpWgwyCbg X-IronPort-AV: E=Sophos;i="4.59,177,1288566000"; d="scan'208";a="77574445" Received: from outgoing-smtp.namesco.net ([85.233.160.25]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 10 Nov 2010 07:59:41 +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 1PG4eh-0001hf-3s; Wed, 10 Nov 2010 06:59:39 +0000 Received: from root by arion.hosts.co.uk with local (Exim 4.69) (envelope-from ) id 1PG4eg-00039X-Ol; Wed, 10 Nov 2010 06:59:38 +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: <1289372378510@names.co.uk> Date: Wed, 10 Nov 2010 06:59:38 +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 yminsky:01 ocaml:01 wrote:01 avoids:01 avoids:01 caml-list:01 explicitly:02 argument:02 functional:02 mentioning:03 programming:03 nested:04 generally:04 simpler:05 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