From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: ** X-Spam-Status: No, score=2.3 required=5.0 tests=AWL,RCVD_NUMERIC_HELO, SPF_FAIL autolearn=disabled version=3.1.3 Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 8BB6FBC69 for ; Wed, 21 Feb 2007 23:04:48 +0100 (CET) Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l1LM4lwK011257 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Wed, 21 Feb 2007 23:04:48 +0100 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1HJzZq-0002RT-O6 for caml-list@inria.fr; Wed, 21 Feb 2007 23:04:42 +0100 Received: from 209.213.205.130 ([209.213.205.130]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 21 Feb 2007 23:04:42 +0100 Received: from sds by 209.213.205.130 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 21 Feb 2007 23:04:42 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: Sam Steingold Subject: Re: warning on value shadowing Date: Wed, 21 Feb 2007 17:04:24 -0500 Message-ID: <45DCC1E8.3050807@gnu.org> References: <45DCAE89.1050904@gnu.org> <97C89459-B045-4700-8333-FAE31EC648E0@cs.uni-sb.de> <45DCB558.6000601@podval.org> <45DCBEED.10706@davidb.org> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@sea.gmane.org Cc: Christian Lindig , Caml List X-Gmane-NNTP-Posting-Host: 209.213.205.130 User-Agent: Thunderbird 1.5.0.8 (X11/20061107) In-Reply-To: <45DCBEED.10706@davidb.org> Sender: news X-j-chkmail-Score: MSGID : 45DCC1FF.001 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 45DCC1FF.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; lindig:01 foo:01 quux:01 foo:01 avoided:01 arbitrarily:01 compiler:01 haskell:01 haskell:01 ocaml:01 redefining:01 2007,:98 wrote:01 wrote:01 explicitly:01 David Brown wrote: > Sam Steingold wrote: >> Christian Lindig wrote: >>> On Feb 21, 2007, at 9:41 PM, Sam Steingold wrote: >>> >>>> Proposal: When both foo.ml and bar.ml define zot and quux.ml opens >>>> both Foo and Bar, there should be a warning [..] >>> While I see your concern I think open is best avoided. >> Yes, of course. Alas, I am not at liberty to arbitrarily and >> pervasively change a huge code-reviewed project to satisfy my >> stylistic preferences. I just see no reason for the compiler not to >> issue such a warning. > > One could also argue that this condition is an error. The closest > equivalent in Haskell is erroneous (only when the symbol is > referenced). Of course Haskell gives a lot more control over the > importing or names, and is declarative, so it isn't equivalent at all. It is also an error in Lisp - although there is a well defined way to avoid the error by explicitly specifying who shadows what. http://www.lisp.org/HyperSpec/Body/fun_shadow.html http://www.lisp.org/HyperSpec/Body/sec_11-1-1-2-5.html I think there is a way to treat warnings as errors, so this is covered. > The problem with this as a warning, is that outside of multiple > modules, this scenario is fairly common: > > let x = ... > let x = ... x ... > > Since ocaml uses the most recent declration, this is well defined, as > it is with multiple 'open's. it should be possible to separate 4 situations: 1 cross-module shadowing (warning) 2 redefining a global value in the same file (warning) 3 shadow a global value with a local one (warning) 4 redefine a local value as in your example (no warning) the warnings can be made optional; one may be able to enable them separately (one by one) etc. Sam.