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 90D26BC0A for ; Sat, 19 May 2007 22:19:59 +0200 (CEST) Received: from sccmmhc92.asp.att.net (sccmmhc92.asp.att.net [204.127.203.212]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l4JKJwWm028968 for ; Sat, 19 May 2007 22:19:59 +0200 Received: from [192.168.0.104] (12-208-242-210.client.mchsi.com[12.208.242.210]) by sccmmhc92.asp.att.net (sccmmhc92) with SMTP id <20070519201957m9200e0iroe>; Sat, 19 May 2007 20:19:57 +0000 Mime-Version: 1.0 (Apple Message framework v752.3) In-Reply-To: <1179579512.18119.36.camel@rosella.wigram> References: <1179543365.26755.33.camel@rosella.wigram> <464E8B1B.7080800@starynkevitch.net> <1179579512.18119.36.camel@rosella.wigram> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: Content-Transfer-Encoding: 7bit From: Jonathan Bryant Subject: Re: [Caml-list] tail rec Date: Sat, 19 May 2007 16:19:02 -0400 To: caml-list@yquem.inria.fr X-Mailer: Apple Mail (2.752.3) X-Miltered: at concorde with ID 464F5BEE.003 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; compiler:01 recursion:01 compiler:01 syntax:01 rec:01 rec:01 caml-list:01 tail:01 tail:01 let:03 let:03 silly:10 except:10 optimize:10 idea:12 >>> 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? Or would it hinder it? --Jonathan