from Haskell Programming from First Principles
- Haskell is a programming language.
- Functions are only called when they are actually needed, so you can handle arrays with an infinite number of elements.
- For example, the two expressions below are equivalent because of lazy evaluation:
- take [13,26,..24*13]
- take 24 [13,26..] (an array with an infinite number of elements)
- Both expressions only process the first 24 elements of the infinite array.
- Since Haskell assumes arrays of infinite length, functions like cycle and repeat in Haskell return infinite arrays (with the assumption that you will use take to truncate them).
- This concept of lazy evaluation is similar to how humans do mathematics.
- Even if you have an infinite sequence of even numbers, evaluation only occurs when you try specific numbers.
- #infinite sets