List Info

Thread: "ocaml_beginners"::[] Operators revisited




"ocaml_beginners"::[] Operators revisited
user name
2006-10-15 19:11:01

Hi folks,

I want to discuss the subject of operator (re)definition yet another
time. This is because most tutorials and books I have read tell you how
to (re)define infix operators but almost nothing about prefix operators,
or valid syntax, precedence and associativity of the (re)defined
operators. From my own simple experiments with the toploop it soon
seemed obvious that custom prefix operators can be defined too, so I
gave a look at the grammar:

infix-symbol ::= (= ∣ < ∣ > ∣ ∣ ^ ∣ | ∣ & ∣ + ∣ - ∣ * ∣ / ∣ $ ∣ %)
{ operator-char }

prefix-symbol ::= (! ∣ ? ∣ ~) { operator-char }

operator-char ::= ! ∣ $ ∣ % ∣ & ∣ * ∣ + ∣ - ∣ . ∣ / ∣ : ∣ < ∣ = ∣ > ∣ ?
∣ ∣ ^ ∣ | ∣

Right. So my guess is that when you (re)define an operator consisting of
a prefix-symbol followed by zero or more operator-chars, you get a
custom prefix operator. The same can be said for infix operators and
infix-symbol. My experiments seem to confirm this supposition. Now for
the associativity/precedence part: they're determined by the starting
character(s) according to the table given in section 6.7 (Expressions)
of "The Objective Caml language&quot;.

More remarks can be done about using operators defined by modules but I
know there is another thread in this list addressing that topic. And
there is the camlp4 stuff too, although it's pretty more advanced.

Perhaps a brief howto or a wiki page could be written about operators in
ocaml. It would have been helpful for me at least.

Cheers,
Carlos.




__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

__._,_.___
.

__,_._,___
"ocaml_beginners"::[] Operators revisited
user name
2006-10-15 22:03:24

On Sun, 15 Oct 2006, Carlos Pita wrote:

> Perhaps a brief howto or a wiki page could be written about operators in
> ocaml. It would have been helpful for me at least.

It seems you are now the best candidate for writing such a page

Martin

--
Martin Jambon, PhD
http://martin.jambon.free.fr

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )