Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Streams.from
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Nick Grey <nickgrey0112@f...>
Subject: [Caml-list] Streams.from

When a stream is created using Stream.from, is the function f garunteed
to be called with the stream count parameter 0, 1, 2, ...

I would say that it is, but the current documentation doesn't seem to
discount the possibility that the function would say, be called twice
with the same parameter, or with parameters out of sequence.  (I can
think of no reason why this would actually happen, I'm just saying the
docs don't discount it.)

The reason that I ask is because it is sometimes useful to pass to from
a function which simply returns the next value in the stream, without
referring to the stream count.  (E.g. because the value can't actually
be computed from the stream count, but comes from some internal state.)
In this case, if the function were to be called repeatedly with the same
parameter, or with the parameters out of sequence, bad things would

I know this is a bit (very? :-) ) pedantic, I'm just slightly uneasy writing code
that makes an assumption about the way a module works.  (After all, the
point of modular programming is that one should not make assumptions
other than those given in the interface/docs.)

Possibly remedies would be to tighten up the documentation of
Stream.from, or to add another version of from which doesn't take the
stream count as a parameter.

Suggestion for change in documentation:

Add at end:
f is called exactly once for each stream element created, and a stream
element is never created until all preceding elements have been created.

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: