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 RAA23273; Tue, 21 Aug 2001 17:38:07 +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 RAA23005 for ; Tue, 21 Aug 2001 17:38:06 +0200 (MET DST) Received: from caroubier.wanadoo.fr (smtp-rt-6.wanadoo.fr [193.252.19.160]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f7LFc4X22058 for ; Tue, 21 Aug 2001 17:38:05 +0200 (MET DST) Received: from citronier.wanadoo.fr (193.252.19.222) by caroubier.wanadoo.fr; 21 Aug 2001 17:38:03 +0200 Received: from debian (217.109.147.245) by citronier.wanadoo.fr; 21 Aug 2001 17:37:34 +0200 Received: from moi by debian with local (Exim 3.32 #1 (Debian)) id 15ZCVq-0000yI-00 for ; Tue, 21 Aug 2001 16:28:14 +0200 To: caml-list@inria.fr Subject: Re: [Caml-list] real lazy? References: <200108211337.f7LDbGl36930@givry.rennes.enst-bretagne.fr> From: Remi VANICAT Date: 21 Aug 2001 16:28:13 +0200 In-Reply-To: <200108211337.f7LDbGl36930@givry.rennes.enst-bretagne.fr> Message-ID: <87pu9pa3nm.dlv@wanadoo.fr> User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.0.104 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Francis Dupont writes: > 3- streams (aka lazy lists) > > open Lazy > (* to get type t and function force *) you could use Lazy.force and Lazy.t > > type 'a cell = Nil | Cons of 'a * 'a stream > and 'a stream = 'a cell Lazy.t > > but this type is not really polymorphic: > > «lazy Nil» has type «'_a cell Lazy.status ref» i.e. «'_a stream» > not «'a stream» as it should be! it's not such a trouble. You could write a little function : let nil () = lazy Nil and create a new empty stream each time you need it. You could also use ocaml stream : (of type Stream.t, see the doc of the modules, and thing about ocaml extension in the manual.) It is not exactly the same, but it's quite useful. > > So in place of a module Stream I had to write a functor Stream > (with «sig type t end» as the argument signature) in order to > fix the type of elements of streams. Argh!! i don't believe that a functor is such a trouble. and you can easily make otherwise. > The real purpose of streams is to write: > > let map f = > let rec mapf s = > lazy begin > match force s with > | Nil -> Nil > | Cons(x,r) -> Cons(f x,mapf r) > end > in mapf > > let rec nat = lazy (Cons(0,map succ nat)) > and so on... let nat = let rec aux n = lazy (Cons(n, aux (n+1))) in aux 0 is much better. -- Rémi Vanicat vanicat@labri.u-bordeaux.fr http://dept-info.labri.u-bordeaux.fr/~vanicat ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr