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 discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 497A4BC0A for ; Sat, 19 May 2007 04:56:12 +0200 (CEST) Received: from ipmail01.adl2.internode.on.net (ipmail01.adl2.internode.on.net [203.16.214.140]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l4J2u9QI014399 for ; Sat, 19 May 2007 04:56:11 +0200 X-IronPort-AV: E=Sophos;i="4.14,554,1170595800"; d="scan'208";a="130963003" 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; 19 May 2007 12:26:08 +0930 Subject: tail rec From: skaller To: caml-list@inria.fr Content-Type: text/plain Date: Sat, 19 May 2007 12:56:05 +1000 Message-Id: <1179543365.26755.33.camel@rosella.wigram> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 464E6749.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; compiler:01 camlp:01 annotation:01 compiler:01 sourceforge:01 rec:01 rec:01 tail:01 tail:01 closure:01 functional:02 programming:03 explicit:03 let:03 let:03 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). [Maybe this can be done with camlp4, though I think it might be hard?] I think this could be useful for newbies learning functional programming, and perhaps even experts looking for performance issues. If a let closure of f is made, a warning is issued, eg: let tailrec f x = let g x = f x in (* WARNING *) 1 + g (x - 1) (* not tail, but not explicit call of f *) The annotation does NOT prove a function is tail rec, but if the compiler bombs, it proves the function is not tail rec. Comments? -- John Skaller Felix, successor to C++: http://felix.sf.net