The two Haskell functions below seems to differ only by whether the index variable is implicit or explicit but the difference in performance is by two orders of magnitude.
This function takes about 0.03 seconds to calculate mfib 30:
let mfib = (map fib [0..] !!)
where
fib 0 = 0
fib 1 = 1
fib x = mfib (x-1) + mfib (x-2)
This function takes about 3 seconds for mfib 30:
let mfib i = map fib [0..] !! i
where
fib 0 = 0
fib 1 = 1
fib x = mfib (x-1) + mfib (x-2)
I'm guessing it has to do with GHC inline rules and have been trying to add inline/noinline pragmas to get matching performance.
EDIT: I understand how doing a lookup into the lazy list can be used to memoize the fib function and why the traditional definition of fib is very slow. I was expecting the memoization to work in the second function as well as the first and don't understand why it is not.