Allows for implementation of infinite lists.
A LazyList has a head and tail. It's expensive to do any operation other then on the head or tail, therefore LazyList is not good for random access. Tipically one goes through the list, discarding the heads until one finds the right value.
Based on Haskell's Data.List
Finite lists:
Appending lists:
Zipping:
Infinite lists:
Repeat:
Iterate from a starting value:
Get first n primes:
drop n first elements:
cycle: repeat same list over and over:
Convert to array:
Fibonacci numbers:
Newton-Raphson Square Roots as is shown in "Why functional programming matters" :
http://www.cs.utexas.edu/~shmat/courses/cs345/whyfp.pdf
Patterns implemeted with lazy lists: