English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Re: [Caml-list] Infix function composition operator
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2010-11-10 (06:59)
From: mark@p...
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
> of OCaml code over the years, and I've seen surprisingly few effective
> of the composition operator.  Somehow, I usually find that code that
> 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