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

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jean-Baptiste Rouquier <jrouquiethearchiveshouldhaveafewantispamtricks@e...>
Subject: Re: [Caml-list] Infix operators
>>I'd like to define [many] infix operators

>I came up with a totally rubbish solution to this: define an "infix-ising"
>operator like so which lets you use "long" operator names made of plain
>characters:
>
>  let (%) a b = b a
>
>  let add a b = a + b
>  let addf a b = a +. b
>
>  5 %add 6
>  10. %addf 12.


I sometimes use it as a "pipe" operator :

let (|>) x f = f x
let () = input_line stdin |> lexer |> parser' |> computation |> pretty_print

instead of

let input = input_line stdin in
let temp = lexer input in
let temp = parser' temp in
let temp = computation temp in
pretty_print temp;;

-- 
Jean-Baptiste Rouquier

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners