From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 81889BB84 for ; Sun, 1 Jun 2008 10:09:26 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ap8AANP1QUjAXQIno2dsb2JhbACBVZA2AQEBAQEBBwUIBxGUdoRX X-IronPort-AV: E=Sophos;i="4.27,573,1204498800"; d="scan'208";a="11398235" Received: from concorde.inria.fr ([192.93.2.39]) by mail2-smtp-roc.national.inria.fr with ESMTP; 01 Jun 2008 10:09:26 +0200 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m5189PKq005171 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Sun, 1 Jun 2008 10:09:26 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ap0AANP1QUjUGyoemmdsb2JhbACBVZA2AQEBAQEIBQgHEQOUc4RX X-IronPort-AV: E=Sophos;i="4.27,573,1204498800"; d="scan'208";a="13039734" Received: from smtp4-g19.free.fr ([212.27.42.30]) by mail1-smtp-roc.national.inria.fr with ESMTP; 01 Jun 2008 10:09:25 +0200 Received: from smtp4-g19.free.fr (localhost.localdomain [127.0.0.1]) by smtp4-g19.free.fr (Postfix) with ESMTP id 83EC33EA0B5 for ; Sun, 1 Jun 2008 10:09:25 +0200 (CEST) Received: from localhost.localdomain (c5850-a2-3-62-147-8-26.dial.proxad.net [62.147.8.26]) by smtp4-g19.free.fr (Postfix) with ESMTP id 7A4CF3EA0DC for ; Sun, 1 Jun 2008 10:09:24 +0200 (CEST) Date: Sun, 1 Jun 2008 08:16:38 +0200 From: Fabrice Marchant To: caml-list@inria.fr Subject: Re: [Caml-list] Compose function for multiple parameters ? Message-ID: <20080601081638.508b8071@free.fr> In-Reply-To: References: <20080531092406.093bd147@free.fr> <20080531101042.25d046ee@free.fr> <20080531180149.04e6ac5e@free.fr> X-Mailer: Claws Mail 3.2.0 (GTK+ 2.12.9; i486-pc-linux-gnu) X-Face: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 48425935.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ens-lyon:01 ocaml:01 orderedtype:01 struct:01 elt:01 compel:98 wrote:01 graph:01 graph:01 caml-list:01 functions:01 jambon:01 jambon:01 omitted:01 defining:02 On Sat, 31 May 2008 23:37:24 +0200 (CEST) Martin Jambon wrote: > >>> (( <<- ) <<- ( <<- ) <<- ( <<- )) > >>> to compose with a 3 parameters function. > >> > >> Personally, I call this obfuscated, not clean. > >> > >> > >> Martin > Sorry Fabrice, I'm realizing that my answer was a bit rude... No problem. > Stuff that is not used frequently or which is used far from its point of > definition should receive identifiers that mean something. So what I would > do is use no operator at all unless you use it more than 5 times in the > same module (more or less). I could rename ( <<-- ) to 'compose2'. > > Defining the 2 ops : > > let ( <<- ) f g x = f (g x) > > let ( <<-- ) f g x y = f (g x y) > My point is: why do you insist on having such operators? In my experience > only the simple composition operator can be useful occasionally, locally. I actually felt a need for them because they improve OCaml terseness. An example where their use seems 'natural' : module Make ( X : Set.OrderedType ) = struct module XSet = Set.Make( X ) module XMap = Map.Make( X ) type elt = X.t type t = XSet.t XMap.t ... (* degree vertice graph *) let degree = XSet.cardinal <<-- XMap.find (* mem_edge origin_vertice aim_vertice graph *) let mem_edge org aim = (XSet.mem aim) <<- (XMap.find org) Bad point : the omitted parameters compel to comment functions about their use. > In other words, it's fun to play with such things, but in production code > it's not useful except in some very special situations. > > > Martin I disagree because I heavily used the compose operators in several programs. But a problem I noticed, using such kind of operators is they decrease a bit speed. Regards, Fabrice