Ticket #6000: fibs.hs

File fibs.hs, 204 bytes (added by guest, 2 years ago)

Haskell implementation

Line 
1{-# LANGUAGE BangPatterns #-}
2
3fib :: Int -> Integer
4fib 0 = 0
5fib 1 = 1
6fib n = fib' 0 1 2 where
7    fib' _ y n' | n' > n = y
8    fib' !x !y !n' = fib' y (x+y) (n'+1)
9
10main = fib 1000000 `seq` return ()