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=1.1 required=5.0 tests=AWL,SPF_SOFTFAIL autolearn=disabled version=3.1.3 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id E675BBB84 for ; Wed, 13 Aug 2008 11:16:18 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AiADAHxCokip5TxXiGdsb2JhbACRdwEBAQ8gnV2GfkCBVQ X-IronPort-AV: E=Sophos;i="4.32,200,1217800800"; d="scan'208";a="15960345" Received: from gateway0.eecs.berkeley.edu ([169.229.60.87]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 13 Aug 2008 11:16:17 +0200 Received: from [10.0.1.5] (136-152-208-53.VPN.Berkeley.EDU [136.152.208.53]) (authenticated bits=0) by gateway0.EECS.Berkeley.EDU (8.14.3/8.13.5) with ESMTP id m7D9Fnu0028418 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); Wed, 13 Aug 2008 02:15:59 -0700 (PDT) In-Reply-To: <9E2C98C8798A487DAE77F20A9DC4F1E8@countertenor> References: <9E2C98C8798A487DAE77F20A9DC4F1E8@countertenor> Mime-Version: 1.0 (Apple Message framework v753.1) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <7C6C7ADD-910D-4C62-92FF-E286F0817FA1@cs.berkeley.edu> Cc: OCaml List Content-Transfer-Encoding: 7bit From: Brighten Godfrey Subject: Re: [Caml-list] Value shadowing Date: Wed, 13 Aug 2008 02:15:53 -0700 To: David Allsopp X-Mailer: Apple Mail (2.753.1) X-Spam: no; 0.00; foo:01 checker:01 bool:01 ocaml:01 shadows:98 wrote:01 caml-list:01 tail:01 tail:01 match:02 let:03 let:03 raise:03 berkeley:04 exit:04 On Aug 13, 2008, at 1:54 AM, David Allsopp wrote: > [ 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 also find that style useful. Sometimes the type changes, but I can recall useful cases where the type doesn't change, e.g., a sequence of various operations on a list. Mock-up: let lst = generate_list_somehow () in let lst = List.filter (fun x -> x > 0) in let lst = List.sort compare lst in ... ~Brighten