* [Caml-list] Associativity precedence for the user-defined operator.
@ 2004-07-23 14:27 Claudio Trento
2004-07-23 14:36 ` Richard Jones
2004-07-23 17:42 ` Jean-Baptiste Rouquier
0 siblings, 2 replies; 4+ messages in thread
From: Claudio Trento @ 2004-07-23 14:27 UTC (permalink / raw)
To: caml-list
Hi,
I've defined a set of new operetors, for instance:
let ( /+/ ) = add_num (where add_num is a function that added two sometype
elements.)
but I don't know if I can set associativity precedence for this operator,
writing: el1 ( /+/ ) el2 ( /+/ ) el3 without parenthesis, what happens?
Cheers,
Claudio
-------------------
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Associativity precedence for the user-defined operator.
2004-07-23 14:27 [Caml-list] Associativity precedence for the user-defined operator Claudio Trento
@ 2004-07-23 14:36 ` Richard Jones
2004-07-23 17:42 ` Jean-Baptiste Rouquier
1 sibling, 0 replies; 4+ messages in thread
From: Richard Jones @ 2004-07-23 14:36 UTC (permalink / raw)
Cc: caml-list
On Fri, Jul 23, 2004 at 04:27:06PM +0200, Claudio Trento wrote:
>
> Hi,
>
> I've defined a set of new operetors, for instance:
>
> let ( /+/ ) = add_num (where add_num is a function that added two sometype
> elements.)
>
> but I don't know if I can set associativity precedence for this operator,
> writing: el1 ( /+/ ) el2 ( /+/ ) el3 without parenthesis, what happens?
The easiest way to control associativity and precedence seems to be to
write a Camlp4 extension. For example here is a Camlp4 extension I
wrote to create some left-associative ('LEFTA') ops:
open Pcaml
EXTEND
expr: AFTER "apply"
[ LEFTA
[ e1 = expr; "map_with"; e2 = expr ->
<:expr< List.map $e2$ $e1$ >>
| e1 = expr; "iter_with"; e2 = expr ->
<:expr< List.iter $e2$ $e1$ >>
| e1 = expr; "filter_with"; e2 = expr ->
<:expr< List.filter $e2$ $e1$ >>
| e1 = expr; "concat_with"; e2 = expr ->
<:expr< List.concat (List.map $e2$ $e1$) >>
| e1 = expr; "apply_with"; e2 = expr ->
<:expr< $e2$ $e1$ >>
]
];
END
Rich.
--
Richard Jones. http://www.annexia.org/ http://www.j-london.com/
Merjis Ltd. http://www.merjis.com/ - improving website return on investment
MAKE+ is a sane replacement for GNU autoconf/automake. One script compiles,
RPMs, pkgs etc. Linux, BSD, Solaris. http://www.annexia.org/freeware/makeplus/
-------------------
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Associativity precedence for the user-defined operator.
2004-07-23 14:27 [Caml-list] Associativity precedence for the user-defined operator Claudio Trento
2004-07-23 14:36 ` Richard Jones
@ 2004-07-23 17:42 ` Jean-Baptiste Rouquier
2004-07-23 19:52 ` John Prevost
1 sibling, 1 reply; 4+ messages in thread
From: Jean-Baptiste Rouquier @ 2004-07-23 17:42 UTC (permalink / raw)
To: caml-list
Claudio Trento wrote:
>Hi,
>
>I've defined a set of new operetors, for instance:
>
>let ( /+/ ) = add_num (where add_num is a function that added two sometype
> elements.)
>
>but I don't know if I can set associativity precedence for this operator,
>writing: el1 ( /+/ ) el2 ( /+/ ) el3 without parenthesis, what happens?
>
The manual says that here you have left associativity. See
http://caml.inria.fr/ocaml/htmlman/manual015.html.
# let ( /+/ ) a b =
Printf.printf "a=%i, b=%i\n%!" a b;
a + b;;
val ( /+/ ) : int -> int -> int = <fun>
# let _ = 1 /+/ 2 /+/ 39;;
a=1, b=2
a=3, b=39
- : int = 42
Cheers,
Jean-Baptiste.
-------------------
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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-07-23 19:52 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-23 14:27 [Caml-list] Associativity precedence for the user-defined operator Claudio Trento
2004-07-23 14:36 ` Richard Jones
2004-07-23 17:42 ` Jean-Baptiste Rouquier
2004-07-23 19:52 ` John Prevost
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox