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=0.4 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE 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 EEDC8BC69 for ; Thu, 22 Feb 2007 01:55:03 +0100 (CET) Received: from rabbit.math.nagoya-u.ac.jp (rabbit.math.nagoya-u.ac.jp [133.6.130.5]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l1M0t21x013171 for ; Thu, 22 Feb 2007 01:55:03 +0100 Received: from localhost (millas [172.16.30.29]) by rabbit.math.nagoya-u.ac.jp (8.12.11/3.7W) with ESMTP id l1M0sfKY026868; Thu, 22 Feb 2007 09:54:41 +0900 (JST) Date: Thu, 22 Feb 2007 09:54:36 +0900 (JST) Message-Id: <20070222.095436.125900161.garrigue@math.nagoya-u.ac.jp> To: sds@gnu.org Cc: caml-list@inria.fr Subject: Re: [Caml-list] warning on value shadowing From: Jacques Garrigue In-Reply-To: <45DCAE89.1050904@gnu.org> References: <45DCAE89.1050904@gnu.org> X-Mailer: Mew version 4.0.69 on Emacs 22.0.50 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 45DCE9E6.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; foo:01 quux:01 foo:01 quux:01 overkill:01 overkill:01 pervasives:01 printf:01 haskell:01 ocaml:01 haskell:01 overloading:01 iirc:01 pervasives:01 stdin:01 From: Sam Steingold > Proposal: > When both foo.ml and bar.ml define zot and quux.ml opens both Foo and > Bar, there should be a warning (when compiling quux) about Foo.zot being > shadowed by Bar.zot (or vice versa, depending on the order of the open > statements). > If you think this is an overkill, please at least consider issuing the > warning when zot is used in quux.ml. > If you think that is also an overkill, please at least consider issuing > the warning when foo=quux. The first one is clearly overkill: if nobody uses zot, then who cares? The second one might be useful, but it creates some problems. For instance, it is common practice to open Format or Unix, and have them intentionally shadow definitions from Pervasives. Should we make an exception for that? But it is not so infrequent to do it with other modules too (for instance open Printf, then Format). For this to be practical, the language would have to be enriched with finer grain control on imports. It has been mentionned that many other languages, including Lisp and Haskell, have warnings or errors with such situations, but there are some differences too. Compared with Lisp, in ocaml the typing avoids most errors: if you forgot shadowing, you will most often get a type error. Haskell has types too, but it also has overloading, which confuse things a bit, and IIRC there are no qualified identifiers, when you want to make explicit which definition you want to use. How bad is the problem in practice? My experience is not so bad. My most common gripe is that when I open Unix, it shadows Pervasives.stdin, and I get type errors... but this is the intended behaviour. I do not remember any situation where the shadowing by a definition with the same type created a semantical error. If I had such an experience, I would probably react like you at first, but then, as other suggested, there are programming styles that avoid this kind of problems. As for the 3rd case, I'm not sure what you are pointing at. You mean shadowing a definition done in the current module by using open? In general, it is suggested to do all the open's at the beginning of the module, except when you intentionnally want to change the namespace somewhere. Jacques Garrigue