Tag Archives: lazy evaluation

Haskell’s Infinite Lists = Fascinating + Mind-Stretching

I like to expose myself to programming languages rooted in different paradigms so that I can expand my skill set, broaden my thinking and learn new ways to solve problems. Lately, I’ve been exploring the world of pure functional programming by studying Haskell.

My object-oriented mind finds the following fascinating:

naturalNumbers = [1..] -- [1,2,3,4,5,…]

This simple statement defines a list starting with 1 and increasing by 1 each step all the way to infinity. The result is not a range that can be enumerated to infinity (for example, 1..1.0/0 using Ruby’s Range class); it’s an actual list that goes to infinity. Continue reading