'Please explain this example in the Stream docs, what is [< >] syntax?

https://ocaml.org/api/Stream.html

val from : (int -> 'a option) -> 'a t

Stream.from f returns a stream built from the function f. To create a new stream element, the function f is called with the current stream count. The user function f must return either Some <value> for a value or None to specify the end of the stream.

Do note that the indices passed to f may not start at 0 in the general case. For example, [< '0; '1; Stream.from f >] would call f the first time with count 2.

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 '?)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source