caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: <mark@proof-technologies.com>
To: <yminsky@gmail.com>, <arlen@noblesamurai.com>
Cc: <caml-list@inria.fr>
Subject: Re: [Caml-list] Infix function composition operator
Date: Wed, 10 Nov 2010 06:59:38 +0000	[thread overview]
Message-ID: <1289372378510@names.co.uk> (raw)

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


             reply	other threads:[~2010-11-10  6:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-10  6:59 mark [this message]
2010-11-10 12:51 ` Jon Harrop
2010-11-14 18:20   ` Till Varoquaux
  -- strict thread matches above, loose matches on Subject: below --
2010-11-10 15:18 mark
2010-11-10 13:44 mark
2010-11-10 14:13 ` Jon Harrop
2010-11-10 16:10   ` Stephan Tolksdorf
2010-11-10 17:41     ` Jon Harrop
2010-11-10 18:52       ` Stephan Tolksdorf
2010-11-10  3:19 Arlen Christian Mart Cuss
2010-11-10  3:45 ` [Caml-list] " Yaron Minsky
2010-11-10  4:37   ` Arlen Christian Mart Cuss
2010-11-10 10:06   ` DS
2010-11-10 13:23 ` Michael Ekstrand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1289372378510@names.co.uk \
    --to=mark@proof-technologies.com \
    --cc=arlen@noblesamurai.com \
    --cc=caml-list@inria.fr \
    --cc=yminsky@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).