Name: Anonymous 2012-01-23 7:24
/program/, help me. I'm learning Haskell, and I love it. What can I do to rectify my correct opinion that functional programming is a wonderful and powerful tool?
memoized_fib = (map fib [0 ..] !!)
where fib 0 = 0
fib 1 = 1
fib n = memoized_fib (n-2) + memoized_fib (n-1)map fib [0 ..] is cached between subsequent calls to the function and because !! will evaluate the elements of the list up to the one requested (and no others) in the right order.