From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA23699 for caml-redistribution; Mon, 22 Mar 1999 15:38:50 +0100 (MET) 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 NAA07637 for ; Mon, 22 Mar 1999 13:53:20 +0100 (MET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.8.7/8.8.7) with ESMTP id NAA28636; Mon, 22 Mar 1999 13:53:17 +0100 (MET) Received: (from vouillon@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id NAA02267; Mon, 22 Mar 1999 13:53:18 +0100 (MET) Message-ID: <19990322135318.08356@pauillac.inria.fr> Date: Mon, 22 Mar 1999 13:53:18 +0100 From: Jerome Vouillon To: Markus Mottl , OCAML Subject: Re: question on recursive types References: <199903211947.UAA20606@miss.wu-wien.ac.at> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Mailer: Mutt 0.89.1 In-Reply-To: <199903211947.UAA20606@miss.wu-wien.ac.at>; from Markus Mottl on Sun, Mar 21, 1999 at 08:47:55PM +0100 Sender: weis Hello, On Sun, Mar 21, 1999 at 08:47:55PM +0100, Markus Mottl wrote: > I am trying to find a useful approach for sending streams of messages > to objects and have come across the following problem (code example): > > class transformer = object (self) > method apply_strm s = > try while true do (Stream.next s) self s done with Stream.Failure -> () > end [...] > Unfortunately, this results in a recursive type, because the elements of > the stream are functions that have to accept the same type of streams > as parameter. [...] The usual trick to avoid explicitely recursive types is to use a type constructor: type 'a t = Stream of ('a -> 'a t -> unit) Stream.t;; class transformer = object (self) method apply_strm s = try while true do (Stream.next s) self (Stream s) done with Stream.Failure -> () end;; -- Jérôme