Haskell's Elegant Fibonacci Implementation in C#
Haskell is a high-level, functional, programming language. Its combination of higher-order functions and lazy evaluation can lead to beautifully elegant algorithm implementations. One such implementation is the Fibonacci series algorithm:
let fib = 1 : 1 : zipWith (+) fib (tail fib)
This creates a variable called fib that contains an infinite sequence of Fibonacci numbers. We could print this variable, but our program would start trying to print an infinite number of elements. A better approach is to choose a finite number of elements from the sequence:
take 10 fib [1,1,2,3,5,8,13,21,34,55]
The above implementation of fib fascinates me, so I decided to try my …continue.