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.9 required=5.0 tests=DNS_FROM_RFC_ABUSE, SPF_NEUTRAL autolearn=disabled version=3.1.3 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 08E47BB84 for ; Wed, 13 Aug 2008 17:05:29 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AokDADqVokjAXQIniGdsb2JhbACBYJAWAQEBDyCkX4FV X-IronPort-AV: E=Sophos;i="4.32,201,1217800800"; d="scan'208";a="28197593" Received: from concorde.inria.fr ([192.93.2.39]) by mail4-smtp-sop.national.inria.fr with ESMTP; 13 Aug 2008 17:05:28 +0200 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m7DF5SYt001783 for ; Wed, 13 Aug 2008 17:05:28 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvcUAMCUokjVBJXyWmdsb2JhbACBYJAMARYCCQgQBaR2gVU X-IronPort-AV: E=Sophos;i="4.32,201,1217800800"; d="scan'208";a="16090279" Received: from outmailhost.telefonica.net (HELO ctsmtpout3.frontal.correo) ([213.4.149.242]) by mail1-smtp-roc.national.inria.fr with ESMTP; 13 Aug 2008 17:03:28 +0200 Received: from NANA.localdomain (83.54.190.14) by ctsmtpout3.frontal.correo (7.3.135) (authenticated as ferferse$telefonica.net) id 489F90840039AF85 for caml-list@inria.fr; Wed, 13 Aug 2008 17:03:27 +0200 Received: from mfp by NANA.localdomain with local (Exim 4.69) (envelope-from ) id 1KTHsk-0001FM-Rj for caml-list@inria.fr; Wed, 13 Aug 2008 17:03:26 +0200 Date: Wed, 13 Aug 2008 17:03:26 +0200 From: Mauricio Fernandez To: caml-list@inria.fr Subject: Re: [Caml-list] Value shadowing Message-ID: <20080813150326.GI6952@NANA.localdomain> Mail-Followup-To: caml-list@inria.fr References: <9E2C98C8798A487DAE77F20A9DC4F1E8@countertenor> <20080813101243.GA2038@annexia.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.17+20080114 (2008-01-14) X-Miltered: at concorde with ID 48A2F838.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; 0100,:01 0100,:01 foo:01 ocaml:01 foo:01 bug:01 clairvoyant:98 wrote:01 wrote:01 caml-list:01 tail:01 reuse:01 match:02 variables:02 variables:02 On Wed, Aug 13, 2008 at 12:04:21PM +0100, David Allsopp wrote: > > On Wed, Aug 13, 2008 at 09:54:36AM +0100, David Allsopp wrote: > > > 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 > > > > I'd find it very counter-intuitive if OCaml behaved like this, and > > annoying if it gave a warning. Just name the variables to be > > different! > > You seem to have missed my point that I wrote the above *in error* so "Just > name the variables to be different!" is a clairvoyant response in this > case... I'm aware that that's what has to change :o) (Somewhat tangentially) I often reuse variable names *in order to avoid errors*, e.g., I prefer let l = foo l in to let l' = foo l in when I have no need for the original l in subsequent code and both l and l' have the same type. This prevents a potential bug (using l instead of l' later). Shadowing is useful when you could code in point-free style but decide to name the intermediate values for clarity. -- Mauricio Fernandez - http://eigenclass.org