Skip to content

Instantly share code, notes, and snippets.

@jprupp
Created May 5, 2012 12:28
Show Gist options
  • Save jprupp/2602003 to your computer and use it in GitHub Desktop.
Save jprupp/2602003 to your computer and use it in GitHub Desktop.
Fibonacci in Haskell
fib :: Int -> Int
fib x
| x < 0 = error ("Can't calculate fib of negative number " ++ show x)
| x == 0 = 0
| x > 0 = accum (x-1) 0 1
where
accum :: Int -> Int -> Int -> Int
accum x y z
| x > 0 = accum (x-1) z (y+z)
| otherwise = z
main = print [(x,fib x) | x <- [0..9]]
@jprupp
Copy link
Author

jprupp commented May 5, 2012

Flexing my functional muscle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment