From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 2FE86BB81 for ; Fri, 2 Dec 2005 10:29:56 +0100 (CET) Received: from zaphod.lost-oasis.net (zaphod.lost-oasis.net [212.85.153.18]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id jB29Ttag006830 for ; Fri, 2 Dec 2005 10:29:56 +0100 Received: from www-data by zaphod.lost-oasis.net with local (Exim 3.36 #1 (Debian)) id 1Ei7Ei-0006P4-00; Fri, 02 Dec 2005 10:29:48 +0100 Received: from 132.166.133.216 (SquirrelMail authenticated user basile@starynkevitch.net) by panel.lost-oasis.net with HTTP; Fri, 2 Dec 2005 10:29:48 +0100 (CET) Message-ID: <55541.132.166.133.216.1133515788.squirrel@panel.lost-oasis.net> In-Reply-To: <20051202200957.2fb14d49.ocaml-erikd@mega-nerd.com> References: <20051202200957.2fb14d49.ocaml-erikd@mega-nerd.com> Date: Fri, 2 Dec 2005 10:29:48 +0100 (CET) Subject: Re: [Caml-list] Reporting on sucess/failure of tail recursion From: basile@starynkevitch.net To: "Erik de Castro Lopo" Cc: caml-list@yquem.inria.fr User-Agent: SquirrelMail/1.4.2 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Miltered: at concorde with ID 43901413.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 recursion:01 basile:01 ocaml:01 recursive:01 recursive:01 compiler:01 ocamlc:01 computes:01 flags:01 ocaml:01 internals:01 compiler:01 behaves:01 rec:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=NO_REAL_NAME autolearn=disabled version=3.0.3 > Say I have a file containing a number of Ocaml functions. > We all know the advantages of tail recursive functions over non-tail > recursive ones and some of us know if a simple function is tail > recursice just by looking at it. However, for more complex functions > it would be really nice if there was a compiler mode that could print > which recursive functions in a file were tail recursive and which were > not. Functions are not tail-recursive, but function *calls* are (or not) tail-recursive. I mean that a given function may have both tail [-recursive] and non-tail [-recursive] calls. Maybe what you are dreaming of is an extension of the -dtypes flag (to ocamlc) which not only computes the type of each expression, but also flags each function *call* as a tail (or not a tail) call. I do agree it would be quite useful (but my knowledge of ocaml internals make me think that it is in principle easy, but in practice would require a lot of changes within the compiler, since tail-rec detection is done in passes near the backend, after the typing.). We could even dream of a let tailrec language construct which behaves like let rec but checks that each recursive call to the function is in fact a tail-recursion. All this is in principle easy to do, but I understand that it might require a significant amount of work which is not the priority of INRIA Cristal team (which is a team of researchers, not of engineers). Regards. -- Basile Starynkevitch http://starynkevitch.net/Basile PS: I've currently got ADSL problems so have difficulties to read my emails.