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 DAA07621; Sat, 12 Apr 2003 03:20:42 +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 DAA07343 for ; Sat, 12 Apr 2003 03:20:41 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from www.duonix.com ([210.113.163.221]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h3C1Kc906726 for ; Sat, 12 Apr 2003 03:20:39 +0200 (MET DST) Received: from hama ([192.168.0.254]) by www.duonix.com (8.12.8/8.11.6) with SMTP id h3C1QBR3016200 for ; Sat, 12 Apr 2003 10:26:11 +0900 (KST) (envelope-from shoh@duonix.com) Message-ID: <000e01c30091$b66bc580$fe00a8c0@hama> From: "SooHyoung Oh" To: "Caml-List" Subject: [Caml-list] [q] on implementing of "memoization" Date: Sat, 12 Apr 2003 10:20:32 +0900 MIME-Version: 1.0 Content-Type: text/plain; charset="ks_c_5601-1987" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Spam: no; 0.00; memoization:01 memo:01 memoize:01 rec':01 generic:01 ocaml:01 rec:01 right-hand:02 shoh:03 soohyoung:03 let:04 duonix:05 source:07 implementing:07 manual:07 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk In testing "memoization" of fib function, it is OK on let rec fib = ... and memo_fib n = memoize fib n;; but it makes the ERROR on let rec fib = ... and memo_fib = memoize fib;; The error message is This kind of expression is not allowed as right-hand side of `let rec' Why does this error occur? I can't find good description on ocaml manual. One more thing: Do you have any idea about ** generic ** and good implementation of memoization? The source is ---------------------------------- let lookup key table = List.assoc key !table;; let insert key value table = table := (key, value) :: !table;; let table = ref [];; let memoize f n = try lookup n table with | Not_found -> let result = f n in insert n result table; result ;; let rec fib = function | 0 -> 0 | 1 -> 1 | n -> memo_fib (n-1) + memo_fib (n-2) and memo_fib n = memoize fib n ;; ---------------------- Thanks a lot! --- SooHyoung Oh ------------------- 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