Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] infix functions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: padiolea@i...
Subject: Re: [Caml-list] infix functions
> On Fri, May 27, 2005 at 10:06:10PM +1200, Jonathan Roewen wrote:
>> Hi,
>>
>> I see some pervasive functions are infix, and I'm wondering if there's
>> any plan to support making any arbitrary infix functions?
>>
>> For instance, the Int32 (etc) modules are horrible to use cause of the
>> prefix functions. These are perfect candidates for being infix. And
>> being an OS project,

Can we access the code of this OS project ?
I know that there is another OS project with caml called funk at
  http://perso.ens-lyon.fr/samuel.mimram/docs/funk_doc/
and another one called House but with haskell
 http://www.cse.ogi.edu/~hallgren/House/
that you might be interested in.

> It's also possible to create infix functions; however you have to use
> the camlp4 preprocessor and your functions become reserved words in
> the language.  Here is an example of an infix function which should
> get you started:
>
> 	open Pcaml
>
> 	EXTEND
> 	   expr: AFTER "apply"
> 	   [ LEFTA
> 	       [ e1 = expr; "map_with"; e2 = expr ->
> 	           <:expr< List.map $e2$ $e1$ >>
> 	       ]
> 	   ];
> 	END
>
> So using that extension you could write code like:
>
> 	list map_with (fun elem -> ...)

I think it is simpler for such cases to have a generic operator such as
let (+>) o f = f o

and then just do
 [1;2;3;4] +> map (fun x -> x+1)
which is reminescent of object notation.