From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 06B7ABB9A for ; Wed, 9 Nov 2005 10:00:10 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id jA99098F002347 for ; Wed, 9 Nov 2005 10:00:09 +0100 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA02357 for ; Wed, 9 Nov 2005 10:00:08 +0100 (MET) Received: from smtp1.adl2.internode.on.net (smtp1.adl2.internode.on.net [203.16.214.181]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id jA99064Z002330 for ; Wed, 9 Nov 2005 10:00:07 +0100 Received: from rosella (ppp7-104.lns1.syd7.internode.on.net [59.167.7.104]) by smtp1.adl2.internode.on.net (8.12.9/8.12.6) with ESMTP id jA9903Oo022427; Wed, 9 Nov 2005 19:30:04 +1030 (CST) (envelope-from skaller@users.sourceforge.net) Subject: Re: Ant: [Caml-list] The "Objective" part of Objective Caml From: skaller To: Brian Hurt Cc: brogoff , caml-list In-Reply-To: References: <20051107214110.46596.qmail@web26805.mail.ukl.yahoo.com> <87acggxguw.fsf@mid.deneb.enyo.de> <1131414473.23991.37.camel@rosella> Content-Type: text/plain Date: Wed, 09 Nov 2005 20:00:02 +1100 Message-Id: <1131526802.13828.76.camel@rosella> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 4371BA99.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 4371BA96.002 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocaml:01 compiler:01 compiler:01 reused:01 compilation:01 'get:98 wrote:01 sourceforge:01 imho:01 compile:01 compile:01 expression:01 expression:01 behaviour:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=ITS_LEGAL autolearn=disabled version=3.0.3 On Tue, 2005-11-08 at 16:04 -0600, Brian Hurt wrote: > Yes. For example, Ocaml will reject this code: > let f n = > if (n > 0) && (is_prime (2*n)) then > "bad idea" > else > false > ;; > > despite the fact that "bad idea" will never, ever be returned (given the > obvious definition of is_prime, anyways). This is an interesting case, IMHO. A related case arose in C++ and was discussed by the committee: something like: int x = 1/0; The question was: is the compiler allowed to reject the program? I believe the current answer is: IF the compiler can prove that this code will necessarily be executed, then the behaviour of the program is undefined anyhow, and so the compiler is allowed to reject the program -- but it is NOT required to. However, IF the compiler cannot prove the code will be executed, then it must compile the program. The interesting thing is that 1/0 is a 'constant expression'. However this is not: int a = 0; int b = 1; int c = b/a; In Felix, certain constructions are *required* to be optimised at compile time. In particular, 1/0 is a 'constant expression' and MUST be calculated at compile time. However, as above, the compiler is not allowed to reject the program, just because a constant expression cannot be calculated -- it has to generate code that aborts the program or something, in case that expression is never elaborated (this was a pain to get right, and probably isn't yet) In particular this is perfectly legal Felix: if true then 1 else 1/0 endif and is REQUIRED to reduce to 1. Similarly: if true then 1 else "Hello" endif is perfectly legal. The 'if/then/else/endif' construction is being reused as a macro processing construction: there is no type error here. So .. it all depends on exactly how the language is specified. BTW: I am not sure I like these preprocessor reduction rules. The idea was to 'get rid' of #if style conditional compilation. Without these kinds of rules, constant folding is effectively impossible. -- John Skaller Felix, successor to C++: http://felix.sf.net