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 TAA30701; Tue, 18 Jun 2002 19:52:22 +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 TAA30421 for ; Tue, 18 Jun 2002 19:52:21 +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 g5IHqLj02227 for ; Tue, 18 Jun 2002 19:52:21 +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 g5IHq9E13892; Tue, 18 Jun 2002 18:52:10 +0100 (BST) Message-ID: <3D0F7369.5010706@htec.demon.co.uk> Date: Tue, 18 Jun 2002 18:52:41 +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: Remi VANICAT 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> <3D0F3099.1060809@htec.demon.co.uk> <87znxs8ytx.dlv@wanadoo.fr> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Remi VANICAT wrote: > > no, an exception can be caused by the evaluation of the function to > memoize. then the result of evaluating the function (which is the Exn) > will be stored. Yes, but assuming you do not intend for the function to be memoized itself to raise an exception, there is no opportunity in the code as given to create an initial Exn. So there is no chance of memoize raising an exception itself. > this memoize function have several problem : > - it is not fully polymorphic (you have '_a type) > - you cannot apply this function to two different function : > [snip] > > the only way I see to resolve all those problem is to make: > > let new_memoize () = > let stow = Hashtbl.create 20 > fun f x -> try > Hashtbl.find stow x > with Not_found -> > let v = f x in > Hashtbl.add stow x v; > v > > each call to new_memoize () will make a new memoize function that > could be apply to one function. > I was, rather, interested in the purpose of Val|Exn in the original. But thanks for this improvement! - 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