Version française
Home     About     Download     Resources     Contact us    
Browse thread
right-associating infix application operator camlp4 extension
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jean-Marie Gaillourdet <jmg@g...>
Subject: Re: [Caml-list] right-associating infix application operator camlp4 extension
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

osiire@k8.dion.ne.jp schrieb:
> Maybe "@" and "^" are right-associated.
> 
> # let ( ^$ ) f x = f x;;
> val ( ^$ ) : ('a -> 'b) -> 'a -> 'b = <fun>
> # print_string ^$ List.fold_left (fun x sum -> sum ^ x) "" ^$ ["1";"2";"3"];;
> 321- : unit = ()
> 
> # let ( @$ )  f x = f x;;
> val ( @$ ) : ('a -> 'b) -> 'a -> 'b = <fun>
> #  print_string @$ List.fold_left (fun x sum -> sum ^ x) "" @$ ["1";"2";"3"];;
> 321- : unit = ()

I think this peace of code make the distinction clearer.

# let (^) a b = a,b;;
val ( ^ ) : 'a -> 'b -> 'a * 'b = <fun>
# let (-) a b = a,b;;
val ( - ) : 'a -> 'b -> 'a * 'b = <fun>

Compare the types of the following to expressions:

# 1 - 2 - 3;;
- - : (int * int) * int = ((1, 2), 3)
# 1 ^ 2 ^ 3;;
- - : int * (int * int) = (1, (2, 3))
#

Is that kind of behaviour documented? I wasn't able to find it in the
docs. Which other operator names are right associative?

Jean-Marie Gaillourdet

- --
"Make everything as simple as possible, but not simpler" (A. Einstein)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFC+a70NIUNP/I5YOgRAmFyAJ46rGSHwECUaSyT1ogA5TJoS7ZAuACfQUKS
5WsMn7EBLe4cBW6WQg+I5wk=
=Yu3m
-----END PGP SIGNATURE-----