caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Compose function for multiple parameters ?
@ 2008-05-31  7:24 Fabrice Marchant
  2008-05-31  8:10 ` [Caml-list] " Fabrice Marchant
  0 siblings, 1 reply; 9+ messages in thread
From: Fabrice Marchant @ 2008-05-31  7:24 UTC (permalink / raw)
  To: caml-list

  Hi !

Defining a compose operator :

let ( <<- ) f g x = f (g x)

allows to abstract from parameter and to handle functions nicely :

f <<- g

  My question is : 
  What would be the correct way with more parameters ?

I do not see anything satisfactory neither multiplying the operators :
let ( <<<- ) f g x y = f (g x y);;
  (That would quickly lead to an unreadable code.)

nor keeping with a one-parameter 'compose' to synthesize what we need :

(( <<- ) f) <<- g

Imho, the former is even the worst.

It would be cooler to write the later on the basis of :
(( <<- ) (( <<- ) f)) g

with some operator that could be used as an unary op to lighten the writing.

  Please what would be possible to do ?

Fabrice


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] Compose function for multiple parameters ?
  2008-05-31  7:24 Compose function for multiple parameters ? Fabrice Marchant
@ 2008-05-31  8:10 ` Fabrice Marchant
  2008-05-31 11:24   ` Martin Jambon
  0 siblings, 1 reply; 9+ messages in thread
From: Fabrice Marchant @ 2008-05-31  8:10 UTC (permalink / raw)
  To: caml-list

> It would be cooler to write the later on the basis of :
> (( <<- ) (( <<- ) f)) g

Sorry, I just discover that this is cleaner :
 (( <<- ) <<- ( <<- ))

and extendable to any number of parameters.

 (( <<- ) <<- ( <<- ) <<- ( <<- ))
to compose with a 3 parameters function.

Fabrice


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] Compose function for multiple parameters ?
  2008-05-31  8:10 ` [Caml-list] " Fabrice Marchant
@ 2008-05-31 11:24   ` Martin Jambon
  2008-05-31 16:05     ` Fabrice Marchant
       [not found]     ` <20080531180149.04e6ac5e@free.fr>
  0 siblings, 2 replies; 9+ messages in thread
From: Martin Jambon @ 2008-05-31 11:24 UTC (permalink / raw)
  To: Fabrice Marchant; +Cc: caml-list

On Sat, 31 May 2008, Fabrice Marchant wrote:

>> It would be cooler to write the later on the basis of :
>> (( <<- ) (( <<- ) f)) g
>
> Sorry, I just discover that this is cleaner :
> (( <<- ) <<- ( <<- ))
>
> and extendable to any number of parameters.
>
> (( <<- ) <<- ( <<- ) <<- ( <<- ))
> to compose with a 3 parameters function.

Personally, I call this obfuscated, not clean.


Martin

--
http://wink.com/profile/mjambon
http://mjambon.com


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] Compose function for multiple parameters ?
  2008-05-31 11:24   ` Martin Jambon
@ 2008-05-31 16:05     ` Fabrice Marchant
  2008-06-01  8:39       ` Florent Monnier
       [not found]     ` <20080531180149.04e6ac5e@free.fr>
  1 sibling, 1 reply; 9+ messages in thread
From: Fabrice Marchant @ 2008-05-31 16:05 UTC (permalink / raw)
  To: caml-list

On Sat, 31 May 2008 13:24:55 +0200 (CEST)
Martin Jambon <martin.jambon@ens-lyon.org> wrote:

> On Sat, 31 May 2008, Fabrice Marchant wrote:
> 
> >> It would be cooler to write the later on the basis of :
> >> (( <<- ) (( <<- ) f)) g
> >
> > Sorry, I just discover that this is cleaner :
> > (( <<- ) <<- ( <<- ))
> >
> > and extendable to any number of parameters.
> >
> > (( <<- ) <<- ( <<- ) <<- ( <<- ))
> > to compose with a 3 parameters function.
> 
> Personally, I call this obfuscated, not clean.
> 
> 
> Martin

  OK, it's far to be perfect - funny at best. But what would be the right way ?

Defining the 2 ops :
let ( <<- ) f g x = f (g x)
let ( <<-- ) f g x y = f (g x y)

is it better ?

Regards,

Fabrice


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] Compose function for multiple parameters ?
       [not found]     ` <20080531180149.04e6ac5e@free.fr>
@ 2008-05-31 21:37       ` Martin Jambon
  2008-06-01  0:04         ` Robert Fischer
  2008-06-01  6:16         ` Fabrice Marchant
  0 siblings, 2 replies; 9+ messages in thread
From: Martin Jambon @ 2008-05-31 21:37 UTC (permalink / raw)
  To: Fabrice Marchant; +Cc: caml-list

On Sat, 31 May 2008, Fabrice Marchant wrote:

> On Sat, 31 May 2008 13:24:55 +0200 (CEST)
> Martin Jambon <martin.jambon@ens-lyon.org> wrote:
>
>> On Sat, 31 May 2008, Fabrice Marchant wrote:
>>
>>>> It would be cooler to write the later on the basis of :
>>>> (( <<- ) (( <<- ) f)) g
>>>
>>> Sorry, I just discover that this is cleaner :
>>> (( <<- ) <<- ( <<- ))
>>>
>>> and extendable to any number of parameters.
>>>
>>> (( <<- ) <<- ( <<- ) <<- ( <<- ))
>>> to compose with a 3 parameters function.
>>
>> Personally, I call this obfuscated, not clean.
>>
>>
>> Martin
>
>  OK, it's far to be perfect - funny at best. But what would be the right way ?
>
> Defining the 2 ops :
> let ( <<- ) f g x = f (g x)
> let ( <<-- ) f g x y = f (g x y)
>
> is it better ?

Sorry Fabrice, I'm realizing that my answer was a bit rude...

My point is: why do you insist on having such operators? In my experience 
only the simple composition operator can be useful occasionally, locally.
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).

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

--
http://wink.com/profile/mjambon
http://mjambon.com


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] Compose function for multiple parameters ?
  2008-05-31 21:37       ` Martin Jambon
@ 2008-06-01  0:04         ` Robert Fischer
  2008-06-01  5:24           ` Fabrice Marchant
  2008-06-01  6:16         ` Fabrice Marchant
  1 sibling, 1 reply; 9+ messages in thread
From: Robert Fischer @ 2008-06-01  0:04 UTC (permalink / raw)
  To: Martin Jambon; +Cc: Fabrice Marchant, caml-list

>>> Martin
>>
>>  OK, it's far to be perfect - funny at best. But what would be the
>> right way ?
>>
>> Defining the 2 ops :
>> let ( <<- ) f g x = f (g x)
>> let ( <<-- ) f g x y = f (g x y)
>>
>> is it better ?


Many displays will turn "--" into an mdash, which will obfuscate the difference between the two
operators.

~~ Robert.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] Compose function for multiple parameters ?
  2008-06-01  0:04         ` Robert Fischer
@ 2008-06-01  5:24           ` Fabrice Marchant
  0 siblings, 0 replies; 9+ messages in thread
From: Fabrice Marchant @ 2008-06-01  5:24 UTC (permalink / raw)
  To: caml-list

On Sat, 31 May 2008 19:04:05 -0500
Robert Fischer <robert@fischerventure.com> wrote:

> >> let ( <<-- ) f g x y = f (g x y)

> Many displays will turn "--" into an mdash, which will obfuscate the difference between the two
> operators.
> 
> ~~ Robert.

  Thanks ! Moreover, I discovered on another X terminal, that the aspect of the operator strongly changed due to a different gap between the 2 "-".

Regards,

Fabrice


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] Compose function for multiple parameters ?
  2008-05-31 21:37       ` Martin Jambon
  2008-06-01  0:04         ` Robert Fischer
@ 2008-06-01  6:16         ` Fabrice Marchant
  1 sibling, 0 replies; 9+ messages in thread
From: Fabrice Marchant @ 2008-06-01  6:16 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] Compose function for multiple parameters ?
  2008-05-31 16:05     ` Fabrice Marchant
@ 2008-06-01  8:39       ` Florent Monnier
  0 siblings, 0 replies; 9+ messages in thread
From: Florent Monnier @ 2008-06-01  8:39 UTC (permalink / raw)
  To: caml-list

Fabrice Marchant a écrit :
...
> Defining the 2 ops :
> let ( <<- ) f g x = f (g x)
> let ( <<-- ) f g x y = f (g x y)
>
> is it better ?


let ( <>- ) f g x = f (g x)
let ( <><>- ) f g x y = f (g x y)
let ( <><><>- ) f g x y z = f (g x y z)

perhaps?
(more easy to count the number of caracters with this kind of pattern)

-- 
Cheers
Florent


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2008-06-01  8:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-31  7:24 Compose function for multiple parameters ? Fabrice Marchant
2008-05-31  8:10 ` [Caml-list] " Fabrice Marchant
2008-05-31 11:24   ` Martin Jambon
2008-05-31 16:05     ` Fabrice Marchant
2008-06-01  8:39       ` Florent Monnier
     [not found]     ` <20080531180149.04e6ac5e@free.fr>
2008-05-31 21:37       ` Martin Jambon
2008-06-01  0:04         ` Robert Fischer
2008-06-01  5:24           ` Fabrice Marchant
2008-06-01  6:16         ` Fabrice Marchant

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).