Version française
Home     About     Download     Resources     Contact us    
Browse thread
Compose function for multiple parameters ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Fabrice Marchant <fabricemarchant@f...>
Subject: Re: [Caml-list] Compose function for multiple parameters ?
On Sat, 31 May 2008 23:37:24 +0200 (CEST)
Martin Jambon <martin.jambon@ens-lyon.org> 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