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 QAA32185; Mon, 17 Jun 2002 16:07:59 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA31686 for caml-list@pauillac.inria.fr; Mon, 17 Jun 2002 16:07:58 +0200 (MET DST) 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 PAA31595 for ; Mon, 17 Jun 2002 15:56:06 +0200 (MET DST) Received: from n05.sp.go.dlr.de (n05.sp.go.dlr.de [129.247.28.2]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g5HDu5125423 for ; Mon, 17 Jun 2002 15:56:05 +0200 (MET DST) Received: (from brosenau@localhost) by n05.sp.go.dlr.de (8.11.6/8.11.6) id g5HDu5u19866; Mon, 17 Jun 2002 15:56:05 +0200 From: Benedikt Rosenau Message-Id: <200206171356.g5HDu5u19866@n05.sp.go.dlr.de> Subject: [Caml-list] Memoizing (was: static variables...) To: caml-list@inria.fr Date: Mon, 17 Jun 2002 15:56:04 +0200 (DFT) Cc: vanicat@labri.u-bordeaux.fr In-Reply-To: <87k7oyreva.dlv@wanadoo.fr> from "Remi VANICAT" at Jun 17, 2002 01:19:21 AM X-Mailer: ELM [version 2.5 PL3] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Remi Vanicat wrote: [...] > let memoize f = > let stow = Hashtbl.create 20 in > fun x -> begin > if not (Hashtbl.mem stow x) then begin > try (let v = f x in Hashtbl.replace stow x (Val v)) > with e -> Hashtbl.replace stow x (Exn e) > end; > match Hashtbl.find stow x with > | Val x -> x > | Exn e -> raise e > end I tried to memoize the Ackermann function # let rec ack m n = if m = 0 then n + 1 else if n = 0 then ack (m - 1) 1 else ack (m - 1) (ack m (n - 1)) val ack : int -> int -> int = # let my_ack = memoize ack;; val my_ack : int -> int -> int = The type checker deals with the 'a being an (int -> int). However, I noticed no speedup. So, I transformed the Ackermann to the tupled version, ie "let ackermann (m, n)...", but to no avail. What is the mistake? Regards, Benedikt ------------------- 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