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 QAA18444; Wed, 19 Jun 2002 16:43:02 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 QAA18141 for ; Wed, 19 Jun 2002 16:43:00 +0200 (MET DST) Received: from sunny.pacific.net.au (sunny.pacific.net.au [203.25.148.40]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g5JEgwj08653 for ; Wed, 19 Jun 2002 16:42:59 +0200 (MET DST) Received: from wisma.pacific.net.au (wisma.pacific.net.au [210.23.129.72]) by sunny.pacific.net.au with ESMTP id g5JEguZr004918; Thu, 20 Jun 2002 00:42:56 +1000 (EST) Received: from ozemail.com.au (ppp4.dyn17.pacific.net.au [61.8.17.4]) by wisma.pacific.net.au with ESMTP id AAA20530; Thu, 20 Jun 2002 00:42:54 +1000 (EST) Message-ID: <3D10986D.2060801@ozemail.com.au> Date: Thu, 20 Jun 2002 00:42:53 +1000 From: John Max Skaller User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.2.1) Gecko/20010901 X-Accept-Language: en-us MIME-Version: 1.0 To: William Lovas CC: caml-list@inria.fr Subject: Re: [Caml-list] Memoizing (was: static variables...) References: <87k7oyreva.dlv@wanadoo.fr> <200206171356.g5HDu5u19866@n05.sp.go.dlr.de> <20020618084006.GA8596@force.stwing.upenn.edu> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk William Lovas wrote: > > let recfib recfib = function > | 0 | 1 -> 1 > | n -> recfib (n-1) + recfib (n-2);; > > >Does anyone have any thoughts on this? Am i missing something obvious? > let fib = ref (function | _ -> 1);; fib := function | 0 | 1 -> 1 | n-> !fib (n-1) + !fib (n-2) ;; let memo h f x = (if not (Hashtbl.mem h x) then Hashtbl.add h x (f x); Hashtbl.find h x);; let h = Hashtbl.create 97;; fib := memo h !fib;; -- John Max Skaller, mailto:skaller@ozemail.com.au snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia. voice:61-2-9660-0850 ------------------- 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