'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 freturns a stream built from the functionf. To create a new stream element, the functionfis called with the current stream count. The user functionfmust return eitherSome <value>for a value orNoneto specify the end of the stream.Do note that the indices passed to
fmay not start at0in the general case. For example,[< '0; '1; Stream.from f >]would callfthe 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 '?)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
