Created
December 29, 2014 14:54
-
-
Save parroty/f36683c7bea33423acb0 to your computer and use it in GitHub Desktop.
Fibonacci on Haskell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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