Skip to content

Instantly share code, notes, and snippets.

@funrep
Created September 28, 2013 17:03
Show Gist options
  • Save funrep/6744145 to your computer and use it in GitHub Desktop.
Save funrep/6744145 to your computer and use it in GitHub Desktop.
-- defines the fibonacci function, takes an integer and returns the fibonacci number
fib :: Int -> Int
fib n = if n <= 2 then
n
else fib (n - 1) + fib (n - 2)
-- define a infinit list of all fibonacci numbers
fibs :: [Int]
fibs = map fib [1..]
-- prints the tenth number in the list of all fibonacci numbers
main = print (fibs !! 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment