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 QAA14050; Wed, 7 May 2003 16:31:28 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA13305 for ; Wed, 7 May 2003 16:31:27 +0200 (MET DST) Received: from plover.atdesk.com (plover.atdesk.com [204.130.247.254]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h47EVQT02245 for ; Wed, 7 May 2003 16:31:26 +0200 (MET DST) Received: from explicit.atdesk.com (explicit.atdesk.com [172.30.40.54]) by plover.atdesk.com (8.11.6/8.11.6) with ESMTP id h47EVPG09424; Wed, 7 May 2003 10:31:25 -0400 Date: Wed, 7 May 2003 10:31:25 -0400 Message-Id: <200305071431.h47EVPG09424@plover.atdesk.com> Gcc: nnml:mail.sent To: Garry Hodgson Cc: "caml-list@inria.fr" Subject: Re: [Caml-list] why the "rec" in "let rec"? References: <2003050710041052316284@kestrel.sage.att.com> From: Chris Uzdavinis Organization: Automated Trading Desk, LLC X-Spam: no; 0.00; caml-list:01 hodgson:01 recursion:01 ml's:01 compiler:01 chris:01 rec:01 writes:01 recursive:03 let:04 infinite:05 grammar:05 definition:06 forcing:06 optimization:06 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Garry Hodgson writes: > something i was always curious about: why do you need to specify the > "rec" in a "let rec" function definition? as opposed to, say, > having the compiler figure out when a function is recursive? > > is it a compiler/grammar optimization? or to help the user, forcing > them to be precise with recursion? or required by the type system? It affects the name lookup rules. For example: let f x = x let f x = f x The 2nd definition for function f is not an infinite loop. It calls the previously defined version of f, and is thus a more expensive identity function. However: let f x = x let rec f x = f x Now the first function is not used by the second (which, due to the "rec" having been added, is now an infinite loop calling itself.) > do other ML's do it this way? Yes. -- Chris ------------------- 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