Functional pearl: streams and unique fixed points

Streams, infinite sequences of elements, live in a coworld: they are given by a coinductive data type, operations on streams are implemented by corecursive programs, and proofs are conducted using coinduction. But there is more to it: suitably restricted, stream equations possess unique solutions, a fact that is not very widely appreciated. We show that this property gives rise to a simple and attractive proof technique essentially bringing equational reasoning to the coworld. In fact, we redevelop the theory of recurrences, finite calculus and generating functions using streams and stream operators building on the cornerstone of unique solutions. The development is constructive: streams and stream operators are implemented in Haskell, usually by one-liners. The resulting calculus or library, if you wish, is elegant and fun to use. Finally, we rephrase the proof of uniqueness using generalised algebraic data types.

[1]  M. Douglas McIlroy,et al.  The music of streams , 2001, Inf. Process. Lett..

[2]  Graham Hutton,et al.  Proof Methods for Corecursive Programs , 2005, Fundam. Informaticae.

[3]  Thierry Coquand,et al.  Infinite Objects in Type Theory , 1994, TYPES.

[4]  Jan J. M. M. Rutten,et al.  A coinductive calculus of streams , 2005, Mathematical Structures in Computer Science.

[5]  M. Douglas McIlroy,et al.  Power series, power serious , 1999, Journal of Functional Programming.

[6]  Simon L. Peyton Jones,et al.  Simple unification-based type inference for GADTs , 2006, ICFP '06.

[7]  Jan J. M. M. Rutten,et al.  Behavioural differential equations: a coinductive calculus of streams, automata, and power series , 2003, Theor. Comput. Sci..

[8]  Peter Aczel,et al.  A Final Coalgebra Theorem , 1989, Category Theory and Computer Science.

[9]  Jerzy Karczmarczuk,et al.  Generating Power of Lazy Semantics , 1997, Theor. Comput. Sci..

[10]  Peyton Jones,et al.  Haskell 98 language and libraries : the revised report , 2003 .

[11]  Ralf Hinze,et al.  Fun with phantom types , 2003 .