From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id JAA19734; Tue, 6 Apr 2004 09:05:52 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id JAA19726 for ; Tue, 6 Apr 2004 09:05:51 +0200 (MET DST) Received: from smtp3.adl2.internode.on.net (smtp3.adl2.internode.on.net [203.16.214.203]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i3676ejq026093 for ; Tue, 6 Apr 2004 09:06:41 +0200 Received: from [192.168.1.200] (ppp116-94.lns1.syd2.internode.on.net [150.101.116.94]) by smtp3.adl2.internode.on.net (8.12.9/8.12.9) with ESMTP id i3675iJU012009; Tue, 6 Apr 2004 16:35:46 +0930 (CST) Subject: Re: [Caml-list] failwith, raise and type inference From: skaller Reply-To: skaller@users.sourceforge.net To: Christophe TROESTLER Cc: "O'Caml Mailing List" In-Reply-To: <20040406.031524.77866470.debian00@tiscali.be> References: <200404022028.WAA20083@pauillac.inria.fr> <20040405225238.33087.qmail@web40613.mail.yahoo.com> <20040406.031524.77866470.debian00@tiscali.be> Content-Type: text/plain Message-Id: <1081235143.19232.22.camel@pelican> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 06 Apr 2004 17:05:44 +1000 Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 failwith:01 inference:01 sourceforge:01 2004:99 troestler:01 oddity:01 delivers:99 tilde:01 knuth:01 bracketing:01 9660:01 glebe:01 christophe:01 arithmetic:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Keywords: X-UID: 61 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