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 concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 3994CBC0A for ; Sun, 20 May 2007 00:13:30 +0200 (CEST) Received: from ipmail01.adl2.internode.on.net (ipmail01.adl2.internode.on.net [203.16.214.140]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l4JMDRkR020661 for ; Sun, 20 May 2007 00:13:28 +0200 X-IronPort-AV: E=Sophos;i="4.14,556,1170595800"; d="scan'208";a="131264875" Received: from ppp59-172.lns2.syd6.internode.on.net (HELO [192.168.1.201]) ([121.44.59.172]) by ipmail01.adl2.internode.on.net with ESMTP; 20 May 2007 07:43:24 +0930 Subject: Re: [Caml-list] tail rec From: skaller To: Jonathan Bryant Cc: caml-list@yquem.inria.fr In-Reply-To: References: <1179543365.26755.33.camel@rosella.wigram> <464E8B1B.7080800@starynkevitch.net> <1179579512.18119.36.camel@rosella.wigram> Content-Type: text/plain Date: Sun, 20 May 2007 08:13:20 +1000 Message-Id: <1179612800.6131.2.camel@rosella.wigram> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 464F7687.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; compiler:01 recursion:01 compiler:01 syntax:01 recursive:01 sourceforge:01 wrote:01 rec:01 rec:01 caml-list:01 functions:01 tail:01 tail:01 let:03 let:03 On Sat, 2007-05-19 at 16:19 -0400, Jonathan Bryant wrote: > > >>> I have a silly idea. Introduce a new construction: > >>> > >>> let tailrec f .. > >>> > >>> This is the same as let rec except it checks every direct call to f > >>> is in tail position (and bombs out the compiler if not). > > A question I have about tail recursion in general: > > let f x = (* Do something *) > let g x = (* Do something *); f x > let h x = (* Do something *); g x > > Does the compiler optimize the calls (f x) and (g x) into tail > calls? If so, how would the > > let railrec f x = ... > let tailrec g x = ... > let tailrec h x = ... > > syntax handle/help this? let tailrec would be a bad idea here because these functions aren't recursive. However this form: let g x = (* Do something *); tail f x would assure you the call to f is tailed. -- John Skaller Felix, successor to C++: http://felix.sf.net