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 MAA32447; Wed, 23 Apr 2003 12:53:35 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id MAA31974 for ; Wed, 23 Apr 2003 12:53:33 +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 concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h3NArVH27863 for ; Wed, 23 Apr 2003 12:53:32 +0200 (MET DST) Received: from hama ([192.168.0.254]) by www.duonix.com (8.12.8/8.11.6) with SMTP id h3NAxLRd014464 for ; Wed, 23 Apr 2003 19:59:21 +0900 (KST) (envelope-from shoh@duonix.com) Message-ID: <003901c30986$92677ff0$fe00a8c0@hama> From: "SooHyoung Oh" To: "Caml-List" Subject: [Caml-list] fib with lazy list Date: Wed, 23 Apr 2003 19:53:28 +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; rec':01 lls:99 rec:01 lazy:02 match:02 right-hand:02 shoh:03 soohyoung:03 let:04 implement:05 duonix:05 source:07 type:07 problem:07 solve:07 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk I'm trying to implement "fib" function with lazy list. I met the error with message: File "eg1.ml", line 19, characters 19-35: This kind of expression is not allowed as right-hand side of `let rec' Can anyone solve this problem? ------- source begin --------- type 'a lzlist = LzCons of 'a * 'a lzlist Lazy.t;; let rec forever n = LzCons (n, lazy (forever n));; let rec lzlist f n = LzCons (n, lazy (lzlist f (f n)));; let hd (LzCons (n, l)) = n;; let tl (LzCons (n, l)) = Lazy.force l;; let from n = let add1 m = m + 1 in lzlist add1 n ;; let rec map f lls = LzCons (f (hd lls), lazy (map f (tl lls))) ;; let rec nth lls n = match n with | 0 -> hd lls | n -> nth (tl lls) (n-1) ;; let rec fib_list = map fib (from 0) (* ERROR *) and fib n = match n with | 1 -> 1 | n -> nth fib_list (n-1) + nth fib_list (n-2) ;; let main = fib 5;; -------------- end of source ------------------ --- 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