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 OAA02193; Wed, 23 Apr 2003 14:21:32 +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 OAA02264 for ; Wed, 23 Apr 2003 14:21:31 +0200 (MET DST) Received: from postfix4-2.free.fr (postfix4-2.free.fr [213.228.0.176]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h3NCLUH03006 for ; Wed, 23 Apr 2003 14:21:30 +0200 (MET DST) Received: from montchapet.dijon.fr (lns-p19-18-82-65-117-59.adsl.proxad.net [82.65.117.59]) by postfix4-2.free.fr (Postfix) with SMTP id 21074C095; Wed, 23 Apr 2003 14:21:29 +0200 (CEST) Date: Wed, 23 Apr 2003 14:20:56 +0200 From: Michel Quercia To: "SooHyoung Oh" Cc: caml-list@inria.fr Subject: Re: [Caml-list] fib with lazy list Message-Id: <20030423142056.6e1ff593.michel.quercia@prepas.org> In-Reply-To: <003901c30986$92677ff0$fe00a8c0@hama> References: <003901c30986$92677ff0$fe00a8c0@hama> Organization: CPGE X-Mailer: Sylpheed version 0.8.8 (GTK+ 1.2.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Spam: no; 0.00; quercia:01 prepas:01 caml-list:01 ecrivit:01 rec':01 failwith:01 montchapet:01 21000:01 rec:01 lazy:02 match:02 functionnal:02 right-hand:02 shoh:03 constructor:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Le Wed, 23 Apr 2003 19:53:28 +0900 "SooHyoung Oh" écrivit: > 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? > > 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 rec x = ... x ... is allowed only when the right hand side is a functionnal value or "x is inside an argument of some constructor in the rhs". The following code should work (the constructor here is LzCons) : let rec fib_list = LzCons(1, lazy(map fib (from 1))) and fib n = match n with | n when n < 0 -> failwith "invalid argument" | 0 -> 1 | 1 -> 1 | _ -> nth fib_list (n-1) + nth fib_list (n-2) ;; -- Michel Quercia 23 rue de Montchapet, 21000 Dijon http://michel.quercia.free.fr (maths) http://pauillac.inria.fr/~quercia (informatique) mailto:michel.quercia@prepas.org ------------------- 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