Browse thread
[Caml-list] Associativity precedence for the user-defined operator.
-
Claudio Trento
- Richard Jones
- Jean-Baptiste Rouquier
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Richard Jones <rich@a...> |
| Subject: | Re: [Caml-list] Associativity precedence for the user-defined operator. |
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