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 XAA01153; Tue, 18 Jun 2002 23:52:14 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id XAA02354 for ; Tue, 18 Jun 2002 23:52:13 +0200 (MET DST) Received: from nexus.stwing.upenn.edu (NEXUS.STWING.UPENN.EDU [165.123.132.61]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g5ILqCj06004 for ; Tue, 18 Jun 2002 23:52:12 +0200 (MET DST) Received: from force.stwing.upenn.edu (daemon@force.stwing.upenn.edu [165.123.132.65]) by nexus.stwing.upenn.edu (8.11.6/8.11.6) with ESMTP id g5ILqAB28034 (using TLSv1/SSLv3 with cipher EDH-RSA-DES-CBC3-SHA (168 bits) verified NO) for ; Tue, 18 Jun 2002 17:52:11 -0400 (EDT) Received: (from wlovas@localhost) by force.stwing.upenn.edu (8.11.6/8.11.6) id g5ILqAb04871 for caml-list@inria.fr; Tue, 18 Jun 2002 17:52:10 -0400 (EDT) Date: Tue, 18 Jun 2002 17:52:09 -0400 From: William Lovas To: caml-list@inria.fr Subject: Re: [Caml-list] Memoizing (was: static variables...) Message-ID: <20020618215209.GA4642@force.stwing.upenn.edu> Mail-Followup-To: caml-list@inria.fr References: <87k7oyreva.dlv@wanadoo.fr> <200206171356.g5HDu5u19866@n05.sp.go.dlr.de> <20020618084006.GA8596@force.stwing.upenn.edu> <20020618111613.A30795@absurd.mimuw.edu.pl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20020618111613.A30795@absurd.mimuw.edu.pl> User-Agent: Mutt/1.3.25i Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Tue, Jun 18, 2002 at 11:16:13AM +0200, Jacek Chrzaszcz wrote: > If you write it like this, it works: > > [memoize snipped] > > let recfib recfib = function > | 0 | 1 -> 1 > | n -> recfib (n-1) + recfib (n-2);; > > let fib = memoize recfib;; > > > Now fib 30 is instantaneous! The clue is to contruct a new > hash and a new recursive function once for each application of > memoize. Aha, cool. Thanks! Of course, the limitation here is that you have to change all the recursive definitions to the "delayed binding" sort (aside: does this construct have a name in the theory?), so it's still not completely general. I don't suppose there's much that can be done about that, is there? > PS. In caml you can write anything ;) Of course! It's just a matter of what looks nice :) William ------------------- 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