This site is updated infrequently. For up-to-date information, please visit the new OCaml website at ocaml.org.

[Caml-list] failwith, raise and type inference
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
 Date: 2004-04-06 (07:05) From: skaller Subject: Re: [Caml-list] failwith, raise and type inference
```On Tue, 2004-04-06 at 11:15, Christophe TROESTLER wrote:

> Well I have a little question on this.  The guide says "Arithmetic
> operators: the same rules as in mathematics." but
>
> -. 3.**2.
>
> returns 9. while in math -x^2 means -(x^2) and not (-x)^2 !  I am
> curious why such an oddity.

The correct grammar here is rather nasty.
I use it in Felix, but i'm not at all sure it's
a good idea. The problem comes with:

-x^2, x^-2, x^2^3

which are

-(x^2), x^(-2), x^(2^3)

I use this grammar (which I hope delivers the above),
and is supposed to be the same as FORTRAN:
the nastiness is the 'uplink' from power to
prefixed.

term:
...
prefixed { \$1 }

prefixed:
| PLUS power  { apl \$1 "pos" \$2 }
| MINUS power { apl \$1 "neg" \$2 }
| TILDE power { apl \$1 "compl" \$2 }
| power       { \$1 }

/* exponentiation is right associative */
power:
| superscript STARSTAR prefixed      { apl2 \$2 "pow" [\$1; \$3] }
| superscript { \$1 }

superscript:
...

Knuth found this whole idea so distasteful that
in TeX the rule is that ^ and _ (super and subscript
operators) are unassociative and require explicit
bracketing.

Consider also:

fgx
which usually means f(g(x)) but can also mean (fg)x ...
I'm not sure there *are* any 'usual' rules in maths.

--
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850,
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net

-------------------
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

```