From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA11452; Tue, 13 May 2003 18:36:22 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA11635 for ; Tue, 13 May 2003 18:36:21 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h4DGa5H11323; Tue, 13 May 2003 18:36:05 +0200 (MET DST) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA10869; Tue, 13 May 2003 18:36:05 +0200 (MET DST) From: Pierre Weis Message-Id: <200305131636.SAA10869@pauillac.inria.fr> Subject: Re: [Caml-list] why the "rec" in "let rec"? In-Reply-To: <1052323141.16633.108.camel@ares> from Gerd Stolpmann at "May 7, 103 05:59:01 pm" To: info@gerd-stolpmann.de (Gerd Stolpmann) Date: Tue, 13 May 2003 18:36:05 +0200 (MET DST) Cc: hdaume@ISI.EDU, neelk@alum.mit.edu, caml-list@inria.fr X-Mailer: ELM [version 2.4ME+ PL28 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; pierre:01 weis:01 caml-list:01 gerd:01 stolpmann:01 viktoriastr:01 64293:01 darmstadt:01 rebinding:01 elegantly:01 avoids:01 compiler:01 unify:01 cristal:01 irrelevant:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk [...] > To summarize, the difference between "let" and "let rec" is that they > are based on theories with different strengths, and the language > designers don't want to unify such constructs (IMHO, a good attitude). > > Gerd > -- > ------------------------------------------------------------ > Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany > gerd@gerd-stolpmann.de http://www.gerd-stolpmann.de > ------------------------------------------------------------ An important additional advantage of identifier rebinding is to avoid confusion between the new and old value: the rebinding makes it explicit that the old value is now irrelevant and the language scoping rules will then ensure this property. For example, consider the following (pseudo)-code snippet where we carefully avoid rebinding of i, using a new name j instead: ... i ... let j = i + 1 in ... j ... (* 3 *) In these circumstances, the programmer can confuse i and j, using i instead of j in part (* 3 *). Since, unfortunately, i and j have the same type, the compiler can not detect this error. By contrast, rebinding i elegantly avoids this problem: ... i ... let i = i + 1 in (* 2 *) ... i ... (* 3 *) after (* 2 *) the old value of i is lost (no more accessible) and the code is thus clearer and more robust in my opinion. Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/ ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners