* right-associating infix application operator camlp4 extension
@ 2005-08-06 23:03 Quôc Peyrot
2005-08-07 8:23 ` [Caml-list] " Christian Lindig
2005-08-10 6:21 ` osiire
0 siblings, 2 replies; 8+ messages in thread
From: Quôc Peyrot @ 2005-08-06 23:03 UTC (permalink / raw)
To: caml-list
Hello,
Is there any existing camlp4 extensions to define a $ haskell-like
operator?
example:
f x $ y z would be equivalent to f x (y z)
or
print_endline $ string_of_int x would be equivalent to print_endline
(string_of_int x)
Thanks,
--
Best Regards,
Quôc
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] right-associating infix application operator camlp4 extension
2005-08-06 23:03 right-associating infix application operator camlp4 extension Quôc Peyrot
@ 2005-08-07 8:23 ` Christian Lindig
2005-08-10 6:21 ` osiire
1 sibling, 0 replies; 8+ messages in thread
From: Christian Lindig @ 2005-08-07 8:23 UTC (permalink / raw)
To: Quôc Peyrot; +Cc: caml-list
Am 07.08.2005 um 01:03 schrieb Quôc Peyrot:
> Is there any existing camlp4 extensions to define a $ haskell-like
> operator?
You don't need CamlP4 for this. You could define in OCaml:
let (@@) f x = f x
Now you can write:
print_endline @@ string_of_int x
-- Christian
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] right-associating infix application operator camlp4 extension
2005-08-06 23:03 right-associating infix application operator camlp4 extension Quôc Peyrot
2005-08-07 8:23 ` [Caml-list] " Christian Lindig
@ 2005-08-10 6:21 ` osiire
2005-08-10 7:38 ` Jean-Marie Gaillourdet
1 sibling, 1 reply; 8+ messages in thread
From: osiire @ 2005-08-10 6:21 UTC (permalink / raw)
To: caml-list
Hi.
On Sat, 6 Aug 2005 16:03:55 -0700
In <7B0AADBE-23D8-4C63-ABE7-75360C874E13@lrde.epita.fr>
Quôc Peyrot <chojin@lrde.epita.fr> wrote:
> Is there any existing camlp4 extensions to define a $ haskell-like
> operator?
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 = ()
---
osiire
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] right-associating infix application operator camlp4 extension
2005-08-10 6:21 ` osiire
@ 2005-08-10 7:38 ` Jean-Marie Gaillourdet
2005-08-10 7:50 ` David MENTRE
0 siblings, 1 reply; 8+ messages in thread
From: Jean-Marie Gaillourdet @ 2005-08-10 7:38 UTC (permalink / raw)
To: caml-list
-----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-----
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] right-associating infix application operator camlp4 extension
2005-08-10 7:38 ` Jean-Marie Gaillourdet
@ 2005-08-10 7:50 ` David MENTRE
2005-08-11 3:04 ` Quôc Peyrot
0 siblings, 1 reply; 8+ messages in thread
From: David MENTRE @ 2005-08-10 7:50 UTC (permalink / raw)
To: Jean-Marie Gaillourdet; +Cc: caml-list
Hello,
2005/8/10, Jean-Marie Gaillourdet <jmg@gaillourdet.net>:
> Is that kind of behaviour documented? I wasn't able to find it in the
> docs. Which other operator names are right associative?
See the OCaml manual :
http://caml.inria.fr/pub/docs/manual-ocaml/manual015.html
"""
For infix and prefix symbols, we write ``*...'' to mean ``any symbol
starting with *''.
"""
Associativity is given in the table.
Yours,
d.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] right-associating infix application operator camlp4 extension
2005-08-10 7:50 ` David MENTRE
@ 2005-08-11 3:04 ` Quôc Peyrot
2005-08-11 4:50 ` Stephane Glondu
2005-08-11 10:41 ` Christian Lindig
0 siblings, 2 replies; 8+ messages in thread
From: Quôc Peyrot @ 2005-08-11 3:04 UTC (permalink / raw)
To: caml-list
On Aug 10, 2005, at 12:50 AM, David MENTRE wrote:
> Hello,
>
> 2005/8/10, Jean-Marie Gaillourdet <jmg@gaillourdet.net>:
>
>> Is that kind of behaviour documented? I wasn't able to find it in the
>> docs. Which other operator names are right associative?
>>
>
> See the OCaml manual :
> http://caml.inria.fr/pub/docs/manual-ocaml/manual015.html
Thanks a lot for the answers.
Strangely I couldn't find $ in this documentation, but
let ($) f x = f x
seems to work.
--
Best Regards,
Quôc
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] right-associating infix application operator camlp4 extension
2005-08-11 3:04 ` Quôc Peyrot
@ 2005-08-11 4:50 ` Stephane Glondu
2005-08-11 10:41 ` Christian Lindig
1 sibling, 0 replies; 8+ messages in thread
From: Stephane Glondu @ 2005-08-11 4:50 UTC (permalink / raw)
To: caml-list; +Cc: Quôc Peyrot
On Wednesday 10 August 2005 20:04, Quôc Peyrot wrote:
> Thanks a lot for the answers.
> Strangely I couldn't find $ in this documentation, but
> let ($) f x = f x
> seems to work.
You can use $ as an infix operator according to:
http://caml.inria.fr/pub/docs/manual-ocaml/manual009.html
And it is left-associative, as said in:
http://caml.inria.fr/pub/docs/manual-ocaml/manual015.html
But as far as I understood, Haskell's $ is right-associative.
--
Stephane Glondu
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] right-associating infix application operator camlp4 extension
2005-08-11 3:04 ` Quôc Peyrot
2005-08-11 4:50 ` Stephane Glondu
@ 2005-08-11 10:41 ` Christian Lindig
1 sibling, 0 replies; 8+ messages in thread
From: Christian Lindig @ 2005-08-11 10:41 UTC (permalink / raw)
To: Quôc Peyrot; +Cc: caml-list
On Aug 11, 2005, at 5:04 AM, Quôc Peyrot wrote:
> Thanks a lot for the answers.
> Strangely I couldn't find $ in this documentation, but
> let ($) f x = f x
> seems to work.
This does not work; you need a right associative operator:
# let ($) f x = f x;;
val ( $ ) : ('a -> 'b) -> 'a -> 'b = <fun>
# (-) 3 $ (/) 4 $ 2 ;;
This expression has type int -> int but is here used with type int
# let (@@) f x = f x;;
val ( @@ ) : ('a -> 'b) -> 'a -> 'b = <fun>
# (-) 3 @@ (/) 4 @@ 2 ;;
- : int = 1
This is the right result for 3-(4/2)=1.
-- Christian
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2005-08-11 10:41 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-06 23:03 right-associating infix application operator camlp4 extension Quôc Peyrot
2005-08-07 8:23 ` [Caml-list] " Christian Lindig
2005-08-10 6:21 ` osiire
2005-08-10 7:38 ` Jean-Marie Gaillourdet
2005-08-10 7:50 ` David MENTRE
2005-08-11 3:04 ` Quôc Peyrot
2005-08-11 4:50 ` Stephane Glondu
2005-08-11 10:41 ` Christian Lindig
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).