7

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?

Sergi Mansilla
  • 12,495
  • 10
  • 39
  • 48
  • 1
    This question requires too much omniscience for a humble practitioner to answer :-) I've used streams before in little projects; they're elegant. Lwt seems orthogonal; Core might have a nicer stream implementation. – Jeffrey Scofield May 12 '15 at 18:10
  • @GaintSquid to be clear you're not looking for applications or streams, but rather why they're not 'really' used? If it's the latter i don't know why, but if it's the former I'll answer! – matrixanomaly May 12 '15 at 19:27
  • @matrixanomaly That's right. But I'd be also interested in seeing applications of Streams in real software. – Sergi Mansilla May 12 '15 at 19:59

3 Answers3

11

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

Drup
  • 3,679
  • 13
  • 14
  • That's indeed very telling. Although they propose to make it a library to eliminate dependencies in ocaml itself, right? – Sergi Mansilla May 13 '15 at 12:28
  • The request is for *deprecation*. NOT removal. This is quite different. In any cases, yes, it would be put outside of the compiler (and hopefully, not be used anymore in favor of better libraries). – Drup May 13 '15 at 15:04
  • `Stream` is being [removed in OCaml 5.0](https://github.com/ocaml/ocaml/pull/10896) – mndrix May 24 '22 at 22:38
2

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.

ivg
  • 34,431
  • 2
  • 35
  • 63
1

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)

matrixanomaly
  • 6,627
  • 2
  • 35
  • 58