Re: Functional random data streams Marc Nieper-Wißkirchen 05 May 2020 13:47 UTC

Am Di., 5. Mai 2020 um 15:29 Uhr schrieb John Cowan <xxxxxx@ccil.org>:

[...]

> I have no objection to this, though I doubt the reason given.  The very essence of random numbers is that they aren't pure and functional: they depend not only on the state of the machine, but on the state of the physical universe.  Putting them into a  pure data structure doesn't really change that.

It's subtle. While the creation of a stream of random numbers isn't
pure, accessing the stream once created is pure. It is the latter I
have been talking about. For many applications, the creation of a
single random stream is enough. As everything is pure afterward, we
can then step back and forward in time, which, for some applications,
can be interesting to replay experiments, etc.

In Haskell, thanks to explicit types, it is clearer: In Haskell, the
result type of, say MAKE-RANDOM-BOOLEAN-STREAM, would be the IO monad
applied to the type of streams (lists in Haskell) of booleans. The
appearance of the IO monad shows that the creation is not pure. The
stream itself, however, is just a stream of booleans and can be
manipulated with whatever pure procedures, which, finally, can be
lifted to the IO monad.

> It would be appropriate to provide versions not only for SRFI 41 streams, but also for SRFI 127 lazy sequences.  The three SRFIs were intended (by me, not by Philip Bewig) to form a gradient:
> streams are heavyweight and functional, lazy sequences are middleweight and present a functional interface alongside a visibly stateful one; generators are lightweight, stateful. and without memory.

This makes sense as SRFI 127 lazy sequences are also part of R7RS-large.

[...]

Marc