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 IAA11302 for caml-redistribution; Mon, 22 Mar 1999 08:53:45 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA19266 for ; Sun, 21 Mar 1999 20:48:02 +0100 (MET) Received: from miss.wu-wien.ac.at (miss.wu-wien.ac.at [137.208.107.17]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id UAA16566 for ; Sun, 21 Mar 1999 20:48:01 +0100 (MET) Received: (from mottl@localhost) by miss.wu-wien.ac.at (8.9.0/8.9.0) id UAA20606 for caml-list@inria.fr; Sun, 21 Mar 1999 20:47:55 +0100 (MET) From: Markus Mottl Message-Id: <199903211947.UAA20606@miss.wu-wien.ac.at> Subject: question on recursive types To: caml-list@inria.fr (OCAML) Date: Sun, 21 Mar 1999 20:47:55 +0100 (MET) X-Mailer: ELM [version 2.4 PL21] MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Sender: weis Hello, 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 Method "apply_strm" gets a stream of functions which take as additional parameters the "self"-object and the rest of the stream. These functions are called and they again invoke some method in the "self"-object with the rest of the stream as final parameter (not shown in example - unnecessary for demonstrating problem). This approach would allow very flexible interpretation/execution of message streams as (e.g.) they might be generated by parsers. 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. I have already tried to explicitely specify the type of the stream, but it seems impossible to get rid of the error: File "bla.ml", line 3, characters 43-44: This expression has type (< apply_strm : 'a -> 'b; .. > -> 'c -> 'd) Stream.t as 'a but is here used with type 'c How can I (if possible at all) tell the compiler that 'c and 'a are actually the same type? It doesn't work to use "as" for binding the type of the stream to an identifier and use this one in place of 'c. E.g.: class transformer = object (self : 'self) method apply_strm (s: (('self -> 'a -> unit) Stream.t as 'a)) = try while true do (Stream.next s) self s done with Stream.Failure -> () end The problem can be shown with a shorter, different and now probably not very useful expression: let f (h::t) = h t;; Best regards, Markus Mottl -- Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl