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 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 425BEBC77 for ; Tue, 23 Jan 2007 20:27:17 +0100 (CET) Received: from mail.cs.unm.edu (mail.cs.unm.edu [64.106.20.33]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l0NJRG0Y012849 for ; Tue, 23 Jan 2007 20:27:16 +0100 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.cs.unm.edu (Postfix) with ESMTP id 35138E40DA; Tue, 23 Jan 2007 12:26:45 -0700 (MST) Received: from mail.cs.unm.edu ([127.0.0.1]) by localhost (mail [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 03204-09; Tue, 23 Jan 2007 12:26:44 -0700 (MST) Received: from io.cs.unm.edu (io.cs.unm.edu [64.106.21.21]) by mail.cs.unm.edu (Postfix) with ESMTP id CD49DE40C8; Tue, 23 Jan 2007 12:26:44 -0700 (MST) Date: Tue, 23 Jan 2007 12:26:43 -0700 (MST) From: "William D. Neumann" To: Lucas Holland Cc: caml-list@inria.fr Subject: Re: [Caml-list] Factorial function In-Reply-To: <8C584854-A0BC-4926-A4E7-60620DF4D995@gmail.com> Message-ID: References: <8C584854-A0BC-4926-A4E7-60620DF4D995@gmail.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at cs.unm.edu X-Miltered: at discorde with ID 45B66194.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; factorial:01 recursion:01 stack:01 ocaml:01 ocaml:01 2007,:98 lucas:98 recorder:98 beginners:01 beginners:01 wrote:01 overflows:01 rec:01 caml-list:01 ints:01 On Tue, 23 Jan 2007, 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? It overflows because you don't provide a base case for the recursion (e.g. if n = 1 then 1 else ...), it simply cycles backwards through the ints until the stack is exhausted. Also, if you're just learning OCaml, you may want to use the Caml Beginners list for these types of questions. You con find the list information at: http://groups.yahoo.com/group/ocaml_beginners William D. Neumann --- "There's just so many extra children, we could just feed the children to these tigers. We don't need them, we're not doing anything with them. Tigers are noble and sleek; children are loud and messy." -- Neko Case Life is unfair. Kill yourself or get over it. -- Black Box Recorder