Sergi Mansilla
Sergi Mansilla

Reputation: 12803

Are streams in ocaml really used?

Looking at different ocaml projects, I don't see the built-in Streams in the language ever used. Even in the recent Real World Ocaml book, Streams are not mentioned at all, which is odd.

What's the reason for that? Is it because Lwt or Core superseed them?

Upvotes: 7

Views: 870

Answers (3)

ivg
ivg

Reputation: 35280

Streams were quite good with camlp4 syntax support, without it they are hardly usable at all. So, this was in times long past (although it is still usable, theoretically). As per Drup's reference they would be even removed in a near future (this year) from the core language, and, presumably, will be moved to a standalone library.

This is all not to say, that there is something wrong with streams as a data structure. This is still a very valuable technique used in many OCaml projects, they just use different libraries that implement this. There is Core Sequence, Batteries Enum, Simon Cruanes's gen and sequence packages, Joseph Abrahamson's fstream package to name a few.

Upvotes: 2

matrixanomaly
matrixanomaly

Reputation: 6967

Streams can be used for 'lazy evaluation' in OCaml, especially since OCaml is an eager language, there are definitely useful cases were lazy evaluation (like in Haskell) is desired.

Quoting a lecture in Cornell on streams,

Streams are actually useful in real life. Some applications:

  • compilers reading source file from text
  • network sockets
  • audio and video signal processing
  • voice recognition
  • approximating solutions to equations using convergent series

The provided reference also uses streams to calculate primes lazily, which is very very fast compared to the normal way of computing large primes using the sieve of Eratosthenes. So I feel that streams definitely have their place in the language as it allows for lazy evaluation in OCaml.

Streams were used by my Professor to explain the concept of lazy evaluation in an eager language, the reason it isn't mentioned in Real World OCaml could be that the language itself is eager and streams are not parallel with that concept, and that streams cannot be mutli-threaded. (this is however, speculation)

Upvotes: 1

Drup
Drup

Reputation: 3739

I think I pretty much answer this question in this bug report.

Upvotes: 11

Related Questions