caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Having '<<', why to use '|>' ?
@ 2007-09-17 14:36 Fabrice Marchant
  2007-09-17 18:59 ` [Caml-list] " Eric Cooper
  2007-09-17 22:24 ` Julien Moutinho
  0 siblings, 2 replies; 16+ messages in thread
From: Fabrice Marchant @ 2007-09-17 14:36 UTC (permalink / raw)
  To: caml-list

 Hello !

For f1 and f2 composable functions, writing :   

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

let g1 = f2 << f1

let ( |> ) x f = f x

let g2 = fun x ->
               x
            |> f1
            |> f2  

I usually use '<<' and wonder if we can always supersede '|>' by this operator ?
g1 and g2 are same functions ( not true ? ).
Does it exists a case where the use of '|>' is better ?

Thanks,

 Fabrice
-----------------------------------
Force est de constater que mon post sur Lucky et Camel n'a pas fait un tabac...


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

* Re: [Caml-list] Having '<<', why to use '|>' ?
  2007-09-17 14:36 Having '<<', why to use '|>' ? Fabrice Marchant
@ 2007-09-17 18:59 ` Eric Cooper
  2007-09-17 19:45   ` Fabrice Marchant
  2007-09-17 22:24 ` Julien Moutinho
  1 sibling, 1 reply; 16+ messages in thread
From: Eric Cooper @ 2007-09-17 18:59 UTC (permalink / raw)
  To: caml-list

On Mon, Sep 17, 2007 at 04:36:17PM +0200, Fabrice Marchant wrote:
> let ( << ) f g x = f (g x)
> let ( |> ) x f = f x
> I usually use '<<' and wonder if we can always supersede '|>' by
> this operator ?  Does it exists a case where the use of '|>' is
> better ?

I think it's just a matter of style.  Your |> operator lets you write
"pipelines" similar to the Unix shell, in which evaluation flows
from left to right.  I've typically used this when I'm applying the
function to all its arguments.  I tend to use the traditional
composition operator (your <<), when I'm combining and passing
functional values around.

-- 
Eric Cooper             e c c @ c m u . e d u


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

* Re: [Caml-list] Having '<<', why to use '|>' ?
  2007-09-17 18:59 ` [Caml-list] " Eric Cooper
@ 2007-09-17 19:45   ` Fabrice Marchant
  0 siblings, 0 replies; 16+ messages in thread
From: Fabrice Marchant @ 2007-09-17 19:45 UTC (permalink / raw)
  To: caml-list

> I think it's just a matter of style.  Your |> operator lets you write
> "pipelines" similar to the Unix shell, in which evaluation flows
> from left to right.  I've typically used this when I'm applying the
> function to all its arguments.  I tend to use the traditional
> composition operator (your <<), when I'm combining and passing
> functional values around.

  Thanks a lot !

So I will not add the use of "|>" to my habits. Simply using "<<" will help to keep things simple.

Only two or three operators seems very useful to me :

This one avoids some parentheses and let the code clear.
let ( @ ) f x = f x

The composition operator :
let ( << ) f g x = f @ g x

This one, written like this, is not a true operator, but is very useful to adapt parameters order :
let flip f x y = f y x

This other one, like "|>", doesn't appear to be essential :
let ( >> ) f g = ( << ) g f
( Can't write : let ( >> ) = flip ( << ) instead... )

Please are they other useful operators ?

Regards,

Fabrice


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

* Re: [Caml-list] Having '<<', why to use '|>' ?
  2007-09-17 14:36 Having '<<', why to use '|>' ? Fabrice Marchant
  2007-09-17 18:59 ` [Caml-list] " Eric Cooper
@ 2007-09-17 22:24 ` Julien Moutinho
  2007-09-18  5:39   ` Fabrice Marchant
  1 sibling, 1 reply; 16+ messages in thread
From: Julien Moutinho @ 2007-09-17 22:24 UTC (permalink / raw)
  To: caml-list

Hi,

% cat f.ml4
let ( << ) f g x = f @ g x

% camlp4of -impl f.ml4
File "ghost-location", line 1, characters 0-2:
Quotation not terminated

Just to point out that << interferes with the quotations of Camlp4,
so maybe it is not really wise to use it.

> Force est de constater que mon post sur Lucky et Camel n'a pas fait un tabac...
xD


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

* Re: [Caml-list] Having '<<', why to use '|>' ?
  2007-09-17 22:24 ` Julien Moutinho
@ 2007-09-18  5:39   ` Fabrice Marchant
  2007-09-18  8:53     ` Julien Moutinho
  0 siblings, 1 reply; 16+ messages in thread
From: Fabrice Marchant @ 2007-09-18  5:39 UTC (permalink / raw)
  To: caml-list

On Tue, 18 Sep 2007 00:24:07 +0200
Julien Moutinho <julien.moutinho@gmail.com> wrote:

> Hi,
> 
> % cat f.ml4
> let ( << ) f g x = f @ g x
> 
> % camlp4of -impl f.ml4
> File "ghost-location", line 1, characters 0-2:
> Quotation not terminated

 Thanks for this.

 I didn't knew "camlp4of", staying cowardly with a 3.09 on a debian lenny (no camlp4-extra package).

> Just to point out that << interferes with the quotations of Camlp4,
> so maybe it is not really wise to use it.

  That is actually a problem indeed. What could be safely used as a composition operator instead ?
( <<< ) ? What else ?

Regards,

Fabrice


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

* Re: [Caml-list] Having '<<', why to use '|>' ?
  2007-09-18  5:39   ` Fabrice Marchant
@ 2007-09-18  8:53     ` Julien Moutinho
  2007-09-18  9:09       ` Julien Moutinho
  2007-09-18 14:12       ` Fabrice Marchant
  0 siblings, 2 replies; 16+ messages in thread
From: Julien Moutinho @ 2007-09-18  8:53 UTC (permalink / raw)
  To: caml-list

>   That is actually a problem indeed. What could be safely
> used as a composition operator instead ? ( <<< ) ?
Have a look at this:
	http://caml.inria.fr/pub/docs/manual-ocaml/lex.html#infix-symbol
With the keywords below.

> What else ?
I would personally double the '@':
	let (@@) f g x = f @ g x

Regards.


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

* Re: [Caml-list] Having '<<', why to use '|>' ?
  2007-09-18  8:53     ` Julien Moutinho
@ 2007-09-18  9:09       ` Julien Moutinho
  2007-09-18 14:12       ` Fabrice Marchant
  1 sibling, 0 replies; 16+ messages in thread
From: Julien Moutinho @ 2007-09-18  9:09 UTC (permalink / raw)
  To: caml-list

On Tue, Sep 18, 2007 at 10:53:10AM +0200, Julien Moutinho wrote:
> I would personally double the '@':
> 	let (@@) f g x = f @ g x
Sorry, I have replaced [f (g x)] by [f @ g x] earlier on.


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

* Re: [Caml-list] Having '<<', why to use '|>' ?
  2007-09-18  8:53     ` Julien Moutinho
  2007-09-18  9:09       ` Julien Moutinho
@ 2007-09-18 14:12       ` Fabrice Marchant
  2007-09-18 16:42         ` Jon Harrop
  1 sibling, 1 reply; 16+ messages in thread
From: Fabrice Marchant @ 2007-09-18 14:12 UTC (permalink / raw)
  To: caml-list

  Thanks Julien !

> Have a look at this:
> 	http://caml.inria.fr/pub/docs/manual-ocaml/lex.html#infix-symbol
> With the keywords below.
"Note that the following identifiers are keywords of the Camlp4 extensions and should be avoided for compatibility reasons.

    parser    <<    <:    >>    $     $$    $:
"
So no doubt, I'll edit my old programs and replace "<<".

> > ... a composition operator ... ( <<< ) ?
> > What else ?

> I would personally double the '@':
> 	let (@@) f g x = f @ g x

 ( or f (g x) : it is practically the same thing. )

A 3 chars operator (<<<) doesn't look smart. Simpler is better.
However, about (@@), I preferred to see the direction of the asymmetric composition operator.
( <| ) instead of ( << ) ? Is this a possible idea ?

  But maybe your idea is good. Maths use a kind of small 'o' : (f o g) (x) = f (g (x)).
It's symmetric like (@@), and that doesn't raise any problem.

Cheers,

Fabrice


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

* Re: [Caml-list] Having '<<', why to use '|>' ?
  2007-09-18 14:12       ` Fabrice Marchant
@ 2007-09-18 16:42         ` Jon Harrop
  2007-09-18 20:41           ` skaller
  2007-09-19 19:49           ` Fabrice Marchant
  0 siblings, 2 replies; 16+ messages in thread
From: Jon Harrop @ 2007-09-18 16:42 UTC (permalink / raw)
  To: caml-list

On Tuesday 18 September 2007 15:12:46 Fabrice Marchant wrote:
> A 3 chars operator (<<<) doesn't look smart.

That is actually the F# for lsl. There are also ||| and &&& for bitwise ops.

> Simpler is better. 
> However, about (@@), I preferred to see the direction of the asymmetric
> composition operator. ( <| ) instead of ( << ) ? Is this a possible idea ?

But "<<" is the converse of ">>" (in F#) and "|>" has no converse (or you 
could say that "x |> f" is the converse of "f x").

>   But maybe your idea is good. Maths use a kind of small 'o' : (f o g) (x)
> = f (g (x)). It's symmetric like (@@), and that doesn't raise any problem.

If an OCaml front-end handled unicode with appropriate symbol settings then 
you could use an "o" symbol to mean that infix operator. I think that is a 
good solution, provided you use an editor that supports suitable unicode and 
there is an easy way to enter such things.

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
OCaml for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists/?e


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

* Re: [Caml-list] Having '<<', why to use '|>' ?
  2007-09-18 16:42         ` Jon Harrop
@ 2007-09-18 20:41           ` skaller
  2007-09-19 19:49           ` Fabrice Marchant
  1 sibling, 0 replies; 16+ messages in thread
From: skaller @ 2007-09-18 20:41 UTC (permalink / raw)
  To: Jon Harrop; +Cc: caml-list

On Tue, 2007-09-18 at 17:42 +0100, Jon Harrop wrote:

> If an OCaml front-end handled unicode with appropriate symbol settings then 
> you could use an "o" symbol to mean that infix operator. I think that is a 
> good solution, provided you use an editor that supports suitable unicode and 
> there is an easy way to enter such things.

Actually no, I tried this. I used gvim and ignored the difficulty
of entering the Unicode characters I wanted.

The problem I found was that the fonts were such that the
character was almost unreadable. And I think i tried,
for example, the high school division sign.. 

If you tried that with a 'small o' it would just look like a
small 'o' and not the composition operator.

I think this problem might be fixed with lexical coloring though!


-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


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

* Re: [Caml-list] Having '<<', why to use '|>' ?
  2007-09-18 16:42         ` Jon Harrop
  2007-09-18 20:41           ` skaller
@ 2007-09-19 19:49           ` Fabrice Marchant
  2007-09-19 21:56             ` Vincent Aravantinos
  2007-09-20 13:42             ` Ashish Agarwal
  1 sibling, 2 replies; 16+ messages in thread
From: Fabrice Marchant @ 2007-09-19 19:49 UTC (permalink / raw)
  To: caml-list

On Tue, 18 Sep 2007 17:42:27 +0100
Jon Harrop <jon@ffconsultancy.com> wrote:

>> A 3 chars operator (<<<) doesn't look smart.  
>That is actually the F# for lsl. There are also ||| and &&& for bitwise ops.

  Thanks Jon, happy to read you,

 So, do you think that (<<<) could replace (<<) as a function composition operator ?

> > However, about (@@), I preferred to see the direction of the asymmetric
> > composition operator. ( <| ) instead of ( << ) ? Is this a possible idea ?

> But "<<" is the converse of ">>" (in F#) and "|>" has no converse (or you 
> could say that "x |> f" is the converse of "f x").

Things must keep consistent, you're right. So, ( <| ) instead of ( << )
can't be used.
Julien proposed ( @@ ).

However I saw it was used this way :

let rec ( @@ ) l1 l2 = List.rev_append l1 l2;;  ( Why rec ? )

here :
http://sourceforge.net/project/showfiles.php?group_id=178291

  It would be useful that experimented OCaml people suggest a replacement for the heavily used composition operator ( << ) that is now reserved for camlp4...

 Regards,

Fabrice


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

* Re: [Caml-list] Having '<<', why to use '|>' ?
  2007-09-19 19:49           ` Fabrice Marchant
@ 2007-09-19 21:56             ` Vincent Aravantinos
  2007-09-20 13:42             ` Ashish Agarwal
  1 sibling, 0 replies; 16+ messages in thread
From: Vincent Aravantinos @ 2007-09-19 21:56 UTC (permalink / raw)
  To: Fabrice Marchant; +Cc: caml-list


Le 19 sept. 07 à 21:49, Fabrice Marchant a écrit :

> On Tue, 18 Sep 2007 17:42:27 +0100
> Jon Harrop <jon@ffconsultancy.com> wrote:
>
>>> A 3 chars operator (<<<) doesn't look smart.
>> That is actually the F# for lsl. There are also ||| and &&& for  
>> bitwise ops.
>
>   Thanks Jon, happy to read you,
>
>  So, do you think that (<<<) could replace (<<) as a function  
> composition operator ?
>
>>> However, about (@@), I preferred to see the direction of the  
>>> asymmetric
>>> composition operator. ( <| ) instead of ( << ) ? Is this a  
>>> possible idea ?
>
>> But "<<" is the converse of ">>" (in F#) and "|>" has no converse  
>> (or you
>> could say that "x |> f" is the converse of "f x").
>
> Things must keep consistent, you're right. So, ( <| ) instead of  
> ( << )
> can't be used.
> Julien proposed ( @@ ).
>
> However I saw it was used this way :
>
> let rec ( @@ ) l1 l2 = List.rev_append l1 l2;;  ( Why rec ? )
>
> here :
> http://sourceforge.net/project/showfiles.php?group_id=178291
>
>   It would be useful that experimented OCaml people suggest a  
> replacement for the heavily used composition operator ( << ) that  
> is now reserved for camlp4...

And how about (<<-) or (<--) ?

Cheers,
Vincent

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

* Re: [Caml-list] Having '<<', why to use '|>' ?
  2007-09-19 19:49           ` Fabrice Marchant
  2007-09-19 21:56             ` Vincent Aravantinos
@ 2007-09-20 13:42             ` Ashish Agarwal
  2007-09-20 18:37               ` Gabriel Kerneis
  2007-09-21 20:58               ` Harrison, John R
  1 sibling, 2 replies; 16+ messages in thread
From: Ashish Agarwal @ 2007-09-20 13:42 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 370 bytes --]

>   It would be useful that experimented OCaml people suggest a replacement
for the heavily used composition operator ( << ) that is now reserved for
camlp4...

After reading all your posts and all previous posts I could find, I've
started using (<--) and (-->), but I also wish there was an agreed upon
notation for this. I have no confidence that my choices are good.

[-- Attachment #2: Type: text/html, Size: 423 bytes --]

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

* Re: [Caml-list] Having '<<', why to use '|>' ?
  2007-09-20 13:42             ` Ashish Agarwal
@ 2007-09-20 18:37               ` Gabriel Kerneis
  2007-09-21 20:58               ` Harrison, John R
  1 sibling, 0 replies; 16+ messages in thread
From: Gabriel Kerneis @ 2007-09-20 18:37 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 597 bytes --]

Le Thu, 20 Sep 2007 09:42:02 -0400, "Ashish Agarwal"
<agarwal1975@gmail.com> a écrit :
> >   It would be useful that experimented OCaml people suggest a
> > replacement
> for the heavily used composition operator ( << ) that is now reserved
> for camlp4...
> 
> After reading all your posts and all previous posts I could find, I've
> started using (<--) and (-->), but I also wish there was an agreed
> upon notation for this. I have no confidence that my choices are good.

<-- is already used in pa_monad (but it might not be a problem for you).

Regards,
-- 
Gabriel Kerneis


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

* RE: [Caml-list] Having '<<', why to use '|>' ?
  2007-09-20 13:42             ` Ashish Agarwal
  2007-09-20 18:37               ` Gabriel Kerneis
@ 2007-09-21 20:58               ` Harrison, John R
  2007-09-21 21:44                 ` Karl Zilles
  1 sibling, 1 reply; 16+ messages in thread
From: Harrison, John R @ 2007-09-21 20:58 UTC (permalink / raw)
  To: Ashish Agarwal; +Cc: Caml-list List

[-- Attachment #1: Type: text/plain, Size: 983 bytes --]

Another possibility: I've used "f ** g" for function composition of "f"
and "g"

in some of my code. It seems quite intuitive to me, a sort of
multiplication

operation in the "monoid" of functions. Maybe people accustomed to using

"**" for the power function will find it weird, though.

 

John.

 

________________________________

From: caml-list-bounces@yquem.inria.fr
[mailto:caml-list-bounces@yquem.inria.fr] On Behalf Of Ashish Agarwal
Sent: Thursday, September 20, 2007 6:42 AM
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Having '<<', why to use '|>' ?

 

>   It would be useful that experimented OCaml people suggest a
replacement for the heavily used composition operator ( << ) that is now
reserved for camlp4...

After reading all your posts and all previous posts I could find, I've
started using (<--) and (-->), but I also wish there was an agreed upon
notation for this. I have no confidence that my choices are good.


[-- Attachment #2: Type: text/html, Size: 4268 bytes --]

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

* Re: [Caml-list] Having '<<', why to use '|>' ?
  2007-09-21 20:58               ` Harrison, John R
@ 2007-09-21 21:44                 ` Karl Zilles
  0 siblings, 0 replies; 16+ messages in thread
From: Karl Zilles @ 2007-09-21 21:44 UTC (permalink / raw)
  To: Harrison, John R; +Cc: Ashish Agarwal, Caml-list List

Harrison, John R wrote:
> Another possibility: I’ve used “f ** g” for function composition of
> “f” and “g”

I tend to use that during a hard debugging session.  As in, "The f*****g 
function still doesn't work!"


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

end of thread, other threads:[~2007-09-21 21:42 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-17 14:36 Having '<<', why to use '|>' ? Fabrice Marchant
2007-09-17 18:59 ` [Caml-list] " Eric Cooper
2007-09-17 19:45   ` Fabrice Marchant
2007-09-17 22:24 ` Julien Moutinho
2007-09-18  5:39   ` Fabrice Marchant
2007-09-18  8:53     ` Julien Moutinho
2007-09-18  9:09       ` Julien Moutinho
2007-09-18 14:12       ` Fabrice Marchant
2007-09-18 16:42         ` Jon Harrop
2007-09-18 20:41           ` skaller
2007-09-19 19:49           ` Fabrice Marchant
2007-09-19 21:56             ` Vincent Aravantinos
2007-09-20 13:42             ` Ashish Agarwal
2007-09-20 18:37               ` Gabriel Kerneis
2007-09-21 20:58               ` Harrison, John R
2007-09-21 21:44                 ` Karl Zilles

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