Skip to content

Instantly share code, notes, and snippets.

@TerrorJack
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TerrorJack/1fc8f0eb8a8a45f78f14 to your computer and use it in GitHub Desktop.
Save TerrorJack/1fc8f0eb8a8a45f78f14 to your computer and use it in GitHub Desktop.
Memoization in haskell
fib :: Int -> Integer
fib = head . makefib where
makefib 0 = [0]
makefib 1 = [1,0]
makefib n = (head nextfib + head (tail nextfib)):nextfib where nextfib = makefib $ n - 1
main :: IO ()
main = print $ fib 1000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment