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 UAA08580; Sat, 6 Jul 2002 20:22:57 +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 UAA08404 for ; Sat, 6 Jul 2002 20:22:56 +0200 (MET DST) Received: from nexus.stwing.upenn.edu (NEXUS.STWING.UPENN.EDU [165.123.132.61]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g66IMsf28024 for ; Sat, 6 Jul 2002 20:22:55 +0200 (MET DST) Received: from force.stwing.upenn.edu (daemon@force.stwing.upenn.edu [165.123.132.65]) by nexus.stwing.upenn.edu (8.11.6/8.11.6) with ESMTP id g66IMrU11084 (using TLSv1/SSLv3 with cipher EDH-RSA-DES-CBC3-SHA (168 bits) verified NO) for ; Sat, 6 Jul 2002 14:22:54 -0400 (EDT) Received: (from wlovas@localhost) by force.stwing.upenn.edu (8.11.6/8.11.6) id g66IMrL23756 for caml-list@inria.fr; Sat, 6 Jul 2002 14:22:53 -0400 (EDT) Date: Sat, 6 Jul 2002 14:22:52 -0400 From: William Lovas To: caml-list@inria.fr Subject: Re: [Caml-list] yet another question on lazy lists Message-ID: <20020706182252.GA23247@force.stwing.upenn.edu> Mail-Followup-To: caml-list@inria.fr References: <200207060148.g661mZp06460@orchestra.cs.caltech.edu> <200207061526.RAA06532@pauillac.inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200207061526.RAA06532@pauillac.inria.fr> User-Agent: Mutt/1.3.25i Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sat, Jul 06, 2002 at 05:26:33PM +0200, Pierre Weis wrote: > > Does this mean > > that my "stream_cons" function is useless? > > > > Thanks in advance, > > > > Mike > > No. It means you cannot always use it in place of a constructor > application. Note that a similar phenomenon occurs for pattern > matching: constructors are mandatory, you cannot subtitute them by > equivalent function calls! Actually, i think stream_cons may be useless, due to OCaml's eager evaluation strategy. If you try to delegate the recursion to a function call, the following happens: # let rec constant n = stream_cons n (constant n);; val constant : 'a -> 'a stream = # constant 1;; Stack overflow during evaluation (looping recursion?). ... but the constructor still works: # let rec constant n = Cons (n, lazy (constant n));; val constant : 'a -> 'a stream = # constant 1;; - : int stream = Cons (1, {contents = Lazy.Delayed }) The second argument needs to be treated lazily (which it is, explicitly, using the Cons constructor call), but stream_cons will never achieve that, unless i'm missing something. William P.S. Michael, why not call your type something like `lazy_list', instead of `stream'? The latter conjures up images of stateful Stream.t's, for me at least. Just a thought! ------------------- 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