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 QAA24649; Thu, 12 Jun 2003 16:15:51 +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 QAA22419 for ; Thu, 12 Jun 2003 16:15:50 +0200 (MET DST) Received: from aomori.annexia.org (annexia.force9.co.uk [212.56.101.183]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h5CEFoT10793 for ; Thu, 12 Jun 2003 16:15:50 +0200 (MET DST) Received: from rich by aomori.annexia.org with local (Exim 3.36 #1 (Debian)) id 19QSrl-0003xI-00 for ; Thu, 12 Jun 2003 15:15:49 +0100 Date: Thu, 12 Jun 2003 15:15:49 +0100 To: caml-list@inria.fr Subject: [Caml-list] How to find out if a function is tail recursive? Message-ID: <20030612141549.GA14762@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.4i From: Richard Jones X-Spam: no; 0.00; recursion:01 printf:01 freshmeat:01 ltd:98 ocaml:01 rec:01 overflow:02 london:97 arch:02 stack:02 recursive:03 tail:03 perl:03 let:04 tutorial:05 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk I was writing the section on tail recursion in the OCaml tutorial, and was surprised to find out that the range function (below) isn't tail recursive. Or at least it causes a stack overflow on a large-but-not-unreasonable input value. let rec range a b = if a > b then [] else a :: range (a+1) b ;; let list = range 1 1000000;; Printf.printf "length = %d\n" (List.length list);; Can you tell me why this function isn't tail recursive, and share any useful tips on how to tell whether a function is or is not tail recursive? Thanks, Rich. -- Richard Jones, Red Hat Inc. (London) and Merjis Ltd. http://www.merjis.com/ http://www.annexia.org/ Freshmeat projects: http://freshmeat.net/users/rwmj MONOLITH is an advanced framework for writing web applications in C, easier than using Perl & Java, much faster and smaller, reusable widget-based arch, database-backed, discussion, chat, calendaring: http://www.annexia.org/freeware/monolith/ ------------------- 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