How does Ocaml decide precedence for user-defined operators?

In general, the associativity and precedence of an operator (unless you go out to camlp4 or something) is based on the operator's first character source (look for for "Associativity precedence for the user-defined operator") There is no way to define it explicitly in OCaml (see this and also "User-defined infix operators" on Comparing Objective Caml and Standard ML ) You can use camlp4 or camlp5 to explicitly define the order of infix function. It seems like pa_do can also be an option I tried to write an example but I am not familiar with camlp4 and it is not easy to learn in a few minutes.

In general, the associativity and precedence of an operator (unless you go out to camlp4 or something) is based on the operator's first character. Source (look for for "Associativity precedence for the user-defined operator"). There is no way to define it explicitly in OCaml (see this and also "User-defined infix operators" on Comparing Objective Caml and Standard ML) You can use camlp4 or camlp5 to explicitly define the order of infix function.It seems like pa_do can also be an option.

I tried to write an example but I am not familiar with camlp4 and it is not easy to learn in a few minutes.

Thanks! I'm sort of annoyed that the correct answer is not more useful and/or awesome. I too am not familiar enough with p4/p5 to use it.

– forefinger Jun 5 '10 at 23:56 2 Great link(s). I was going to mention camlp{4,5}, but fixing the precedence of operators was only a mean in the original question. The end was to make the code future-proof.

I doubt any solution involving camlp{4,5} is a good solution towards this goal; it is certainly a dependency I try to avoid, although it is often tempting. – Complicated see bio Jun 6 '10 at 0:59.

It's right in the OCaml manual, section 6.7, scroll down, right before section 6.7.1. The precedence table has some things like +..., which includes any user-defined starting with +. It is not true that it always depends on the first character, as **... has higher precedence than *....

The pa-do syntax extension for OCaml addresses exactly this issue: pa-do.forge.ocamlcore.org/ You can use it to change operator precedence, or, more usefully in this case, use explicit context to change the meaning of operators.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions