https://ocaml.org/api/Stream.html
val from : (int -> 'a option) -> 'a t
Stream.from f
returns a stream built from the functionf
. To create a new stream element, the functionf
is called with the current stream count. The user functionf
must return eitherSome <value>
for a value orNone
to specify the end of the stream.Do note that the indices passed to
f
may not start at0
in the general case. For example,[< '0; '1; Stream.from f >]
would callf
the first time with count2
.
There are two things confusing me about this example.
1.
I had no luck googling for meaning of [< ... >]
syntax. The closest I found was: https://ocaml.org/manual/lex.html#sss:keywords which just says those character sequences are keywords
[< ... ]
seems to be used when printing, but not defining, polymorphic variants: https://ocaml.org/manual/polyvariant.html
If I paste in something like [< '0; '1; >]
I get a syntax error.
So it's currently quite baffling to me what this example is purporting to show.
2.
The example says that [< '0; '1; Stream.from f >]
would call f
the first time with count 2
And I just wonder ... why? how? I can see that 2
follows on from '0
and '1
, but how do those values influence starting value of f
? (and why are they prefixed with '
?)