[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Jerome Vouillon <Jerome.Vouillon@i...> |
| Subject: | Re: question on recursive types |
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