Haskell is a purely functional programming language with strong static typing and lazy evaluation. The Fibonacci sequence is expressed here using an infinite lazy list.

How to test

Prerequisites: GHC (Glasgow Haskell Compiler)

  • Ubuntu/Debian: sudo apt install ghc
  • macOS: brew install ghc
  • All platforms: https://www.haskell.org/downloads/
runghc fibonacci.hs

Expected output:

0
1
1
2
3
5
8
13
21
34

Source Code

fibs :: [Integer]
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)

main :: IO ()
main = mapM_ print (take 10 fibs)

Local Testing Screenshot Image