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.2 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 AFC12BC65 for ; Tue, 23 Jan 2007 20:50:27 +0100 (CET) Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.171]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l0NJoRa5017415 for ; Tue, 23 Jan 2007 20:50:27 +0100 Received: by ug-out-1314.google.com with SMTP id q2so1411961uge for ; Tue, 23 Jan 2007 11:50:27 -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=N+5YYkXhug7ni8nLWwDwTCEa3Vbx7SioSyuukMem/TpRGYIJbbbYOrPlFZBwuVVYAsGK+vw6LCX4IFX4gcPDcDXqSanr5dmdBB5783vHoaWhHsZGP4fGk44jpeYtVeRGnPghGljtBKKGHbqiCdR33ayDc0hZoQtiOdiHRyAWo4M= Received: by 10.82.114.3 with SMTP id m3mr6247405buc.1169581826203; Tue, 23 Jan 2007 11:50:26 -0800 (PST) Received: by 10.82.152.3 with HTTP; Tue, 23 Jan 2007 11:50:20 -0800 (PST) Message-ID: <9d3ec8300701231150p76ecdedhd9d9d7f5be6b2d4e@mail.gmail.com> Date: Tue, 23 Jan 2007 20:50:20 +0100 From: "Till Varoquaux" To: "Lucas Holland" Subject: Re: [Caml-list] Simple factorial Cc: caml-list@yquem.inria.fr In-Reply-To: <3E3A2218-5AA0-445F-A37D-B12EF4A2F9CB@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <3E3A2218-5AA0-445F-A37D-B12EF4A2F9CB@gmail.com> X-j-chkmail-Score: MSGID : 45B66703.000 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 45B66703.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; factorial:01 factorial:01 suboptimal:01 recursive:01 ocaml:01 ocaml:01 cheers:01 o'caml:01 beginner's:01 bug:01 lucas:98 beginners:01 beginners:01 wrote:01 rec:01 Well that's quite a basic error you've got here: You are making an induction without a base case a correct implementation of factorial could be: let rec factorial= function | 0 -> 1 | n -> n*factorial(n-1);; This implementation is suboptimal (not tail recursive etc...) but should be good enough for a beginner. And since we brought this up, you might want to ask those questions on the OCaml Beginners list (ocaml_beginners@yahoogroups.com). It seems a more appropriate place. I also believe some googling could have helped you, for instance (http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html) covers this topic more in depth. Cheers, Till On 1/23/07, Lucas Holland wrote: > Hello, > > I've just started learning O'Caml. I've written a simple factorial > function (no checking whether n is 1 etc.): > > let rec factorial n = > n * factorial (n-1);; > > When I call this function with let's say 5 as an argument, I get an > overflow error message. > > Any ideas? > > chell > > _______________________________________________ > 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 >