The goal of this lecture note is introduce the concept of streams and to illustrate how to program with them.
A stream if a lazy data type for representing infinite sequences of payloads that are constructed on demand. So its declared coinductively and it only has one data constructor:
CoInductive stream (V : Type) : Type :=
SCons : V -> stream V -> stream V.
Property a_stream_does_not_end :
forall (V : Type)
(vs : stream V),
exists (v : V) (vs' : stream V),
vs = SCons V v vs'.
Proof.
intros V [v vs'].
exists v, vs'.
reflexivity.
Qed.
The accompanying .v file contains a variety of streams (e.g., the stream of the successive Peano numbers) and of utilities:
It also contains a variety of examples where streams are indexed, where their prefixes are constructed, where streams are mapped over, etc. These examples illustrate how the same streams can be constructed in different ways.
Next week, we shall formalize this notion of sameness – for how can two infinite sequences that are not constructed yet can be said to be “the same”? Hmm?
Created [09 Apr 2025]