Skip to content

Instantly share code, notes, and snippets.

@parroty
Created December 29, 2014 14:54
Show Gist options
  • Save parroty/f36683c7bea33423acb0 to your computer and use it in GitHub Desktop.
Save parroty/f36683c7bea33423acb0 to your computer and use it in GitHub Desktop.
Fibonacci on Haskell
import System.Environment (getArgs)
main :: IO ()
main = do
args <- getArgs
let n = read $ head args :: Int
putStrLn . show $ fib n
fib :: Int -> Integer
fib 0 = 0
fib 1 = 1
fib n = fib(n - 1) + fib(n - 2)
import System.Environment (getArgs)
main :: IO ()
main = do
args <- getArgs
let n = read $ head args :: Int
putStrLn . show $ fib n
fib :: Int -> Integer
fib = (map fib' [0 ..] !!)
where fib' 0 = 0
fib' 1 = 1
fib' n = fib (n - 1) + fib (n - 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment