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.0 required=5.0 tests=none autolearn=disabled version=3.1.3 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 0D8B4BB84 for ; Wed, 13 Aug 2008 10:54:44 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgABAAg+okjC2fJXo2dsb2JhbACJMYhGAQEBAQEBBwUIBxGlC4FV X-IronPort-AV: E=Sophos;i="4.32,200,1217800800"; d="scan'208";a="13958638" Received: from anchor-post-37.mail.demon.net ([194.217.242.87]) by mail2-smtp-roc.national.inria.fr with ESMTP; 13 Aug 2008 10:54:43 +0200 Received: from orion.metastack.com ([80.177.38.218]) by anchor-post-37.mail.demon.net with esmtp (Exim 4.69) id 1KTC7u-00031X-Pc for caml-list@yquem.inria.fr; Wed, 13 Aug 2008 08:54:43 +0000 Received: from countertenor (cpc1-cmbg10-0-0-cust76.cmbg.cable.ntl.com [81.102.132.77]) (authenticated bits=0) by orion.metastack.com (8.13.4/8.13.3) with ESMTP id m7D8a02u012710 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) for ; Wed, 13 Aug 2008 09:36:01 +0100 From: "David Allsopp" To: "OCaml List" Subject: Value shadowing Date: Wed, 13 Aug 2008 09:54:36 +0100 Organization: MetaStack Solutions Ltd. Message-ID: <9E2C98C8798A487DAE77F20A9DC4F1E8@countertenor> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 11 Thread-Index: Acj9IjaT3dZfuG9DQzeiOz5J7MHIyA== X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512 X-Scanned-By: MIMEDefang 2.63 on 80.177.38.218 X-Spam: no; 0.00; foo:01 checker:01 bool:01 ocaml:01 foo:01 shadows:98 caml-list:01 tail:01 tail:01 caml:02 match:02 warnings:03 let:03 let:03 raise:03 [ There's been at least one recent(ish) discussion on this - [1] ] Suppose I have this piece of code: let foo xs = match xs with x::xs -> if x then xs (* Return the tail of the list *) else xs (* Return the entire list *) | [] -> raise Exit Now, the comments show what's supposed to happen in this function but that's obviously not how it will behave because the entire list [xs] on line 1 is shadowed by the tail of the list [xs] on line 3 so in both cases the tail of the list will be returned. The type checker can do nothing as both have type [bool list]. What would general opinion be if OCaml were to have a warning in this instance - "[xs] on line 3 shadows [xs] on line 1 with the same type"? As noted in the thread below, I too find let x = _ in let x = _ in ... a useful style and would be greatly irritated by a warning on all shadowing - but I think that in most cases for me the type of each [x] is different. I've been stung a couple of times recently by non-contrived versions of the function [foo] (through careless coding, of course - but that's what warnings and type-checkers are about otherwise we'd all be using BCPL!) Thoughts? David [1] http://caml.inria.fr/pub/ml-archives/caml-list/2007/02/f60c7ea8cc0ebdbf9d1d5 6f0623b45a2.en.html