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=1.0 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id C03A3BCB9 for ; Tue, 23 Jan 2007 21:12:54 +0100 (CET) Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.242]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l0NKCrpk021861 for ; Tue, 23 Jan 2007 21:12:54 +0100 Received: by an-out-0708.google.com with SMTP id d26so822117and for ; Tue, 23 Jan 2007 12:12:53 -0800 (PST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=cVhfzC4wzHu6F+JU4B/cRJwATceJythHNrzimJkaUUveDyU4kadVaRoqPzrai5gCx/0lKh9wNQelHMnWMRq2OcovQCbLjpUOhKDsBOqULeUd8ywO7kdEBQqY39L+KmUAGypb7JN3sPqmST0zE8MzyHF2de15g3txfvQW+KmN+OY= Received: by 10.115.33.1 with SMTP id l1mr70258waj.1169583173185; Tue, 23 Jan 2007 12:12:53 -0800 (PST) Received: by 10.115.107.15 with HTTP; Tue, 23 Jan 2007 12:12:53 -0800 (PST) Message-ID: Date: Wed, 24 Jan 2007 09:12:53 +1300 From: "Jonathan Roewen" To: "Lucas Holland" Subject: Re: [Caml-list] Factorial function Cc: caml-list@inria.fr In-Reply-To: <8C584854-A0BC-4926-A4E7-60620DF4D995@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <8C584854-A0BC-4926-A4E7-60620DF4D995@gmail.com> X-j-chkmail-Score: MSGID : 45B66C46.000 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 45B66C46.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; factorial:01 recursive:01 stack:01 rewriting:01 infix:01 beginner's:01 ocaml:01 bug:01 lucas:98 lucas:98 beginners:01 beginners:01 wrote:01 rec:01 caml-list:01 Recursive call to fact is not in tail position. And by overflow, you mean stack overflow. If fact was in tail position, it would loop forever (since there is no base case). You can observe that fact is indeed not in tail position be rewriting the expression without the infix multiplication. ( * ) n (fact (n-1) or: let mul x y = x * y => mul n (fact (n-1)) Anyways, questions like these are better addressed to the beginners list at yahoo groups. Jonathan On 1/24/07, Lucas Holland wrote: > Hi, why does this function: > > let rec fact n = > n * fact (n-1);; > > yield an overflow error if called with n = 5? > > Thanks in advance, > > Lucas > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs >