Site icon Paradite

Constructing infinite sequences using stream

In CS1101S today, we are learning to use stream as a way to delay evaluation. In this way, we can use a function to construct an infinite data structures. For example, integers, Fibonacci sequence.
This stream is achieved by modifying the list concept. The head of the stream is a data value, the tail of the stream is a function to wrap the actual tail value. The function could be returning the reference of the stream itself.

Programming languages which will not evaluate the argument until needed are called lazy . For example, Haskell. Ocaml provides annotations.

This concept is very new and interesting for me as so far I have only seen finite data structures. With infinite data structure, we can do maths involving infinity in programming.

Exit mobile version