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 PAA10061; Tue, 18 Jun 2002 15:07: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 PAA22546 for ; Tue, 18 Jun 2002 15:07:13 +0200 (MET DST) Received: from t2.fast.net.uk (ns1.fast.net.uk [212.42.162.2]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g5ID7Cb24209 for ; Tue, 18 Jun 2002 15:07:12 +0200 (MET DST) Received: from htec.demon.co.uk (adsl-212-42-169-63.fast.net.uk [212.42.169.63]) by t2.fast.net.uk (8.11.6/8.11.4) with ESMTP id g5ID74E82642; Tue, 18 Jun 2002 14:07:05 +0100 (BST) Message-ID: <3D0F3099.1060809@htec.demon.co.uk> Date: Tue, 18 Jun 2002 14:07:37 +0100 From: Christopher Quinn User-Agent: Mozilla/5.0 (compatible; MSIE5.5; Windows 98; X-Accept-Language: en-us, en MIME-Version: 1.0 To: William Lovas CC: caml-list@inria.fr, j.prevost@cs.cmu.edu 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: > Does anyone have any thoughts on this? Am i missing something obvious? > One problem is the creation of the memoized function. it has to be: let rec mack v = memoize (ack mack) v leaving out the v parameter is not possible and hence invocation of memoize is per invocation of mack, hence the hash is recreated empty each time. Putting the hash into the top level solves this but then reclamation would need to be dealt with to avoid leakage. Another point is that ack must be tuple-ized otherwise the memoization hash is a map int -> (int -> int), which means actual results are not being stored. That said, I do not understand the memoization function itself. Perhaps John Prevost could comment on the use of Val|Exn - in particular I cannot see how an initial Exn can be stored in the first place as an exception can only be caused by the presence of an Exn! What is the advantage over specifying it this way? : let stow = Hashtbl.create 20 let memoize f = fun x -> try Hashtbl.find stow x with Not_found -> let v = f x in Hashtbl.add stow x v; v - chris ------------------- 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