From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id XAA07456 for caml-red; Thu, 27 Jul 2000 23:28:52 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA05674 for ; Thu, 27 Jul 2000 20:44:34 +0200 (MET DST) Received: from gdcmail.gemstar.com (slave3056.starsight.com [207.242.103.56]) by concorde.inria.fr (8.10.0/8.10.0) with ESMTP id e6RIiX521156 for ; Thu, 27 Jul 2000 20:44:33 +0200 (MET DST) Received: by gdcmail with Internet Mail Service (5.5.2650.21) id <367R9AZW>; Thu, 27 Jul 2000 11:41:02 -0700 Message-ID: <95C632784DAFD31183CF00C00D015099060207@GDCMAIL2> From: Lenny Gray Reply-To: lenny@aliveness.com To: "'caml-list@inria.fr'" Subject: re: help an o'caml beginner Date: Thu, 27 Jul 2000 11:43:41 -0700 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2650.21) Content-Type: text/plain Sender: weis@pauillac.inria.fr At 11:51 7/26/2000 -0600, John BEPPU wrote: > > ... > >If anyone out there could implement an O'Caml fibonacci number >generator that doesn't make redundant calculations, I would really >appreciate it. I just need something to study. Of course a trivial approach would be to accept the fact that O'Caml _has_ true assignable variables, via references. However, since you sound like you want the _functional_ answer, the insight you're looking for is: let rec f v1 v2 i = if i=0 then v2 else f v2 (v1+v2) (i-1);; then: f 0 1 0 == 1 f 0 1 1 == 1 f 0 1 2 == 2 ... f 0 1 10 == 89 - Lenny -