Hello, I’d like help with a beginner question, please. I am following this example Memoization - HaskellWiki.
First, it is amazing that memoization is ‘induced’ by using the fixed point combinator, but perhaps that isn’t surprising to a computer scientist.
My question is to do the ‘memoization function’:
memo :: (Int -> a) -> (Int -> a)
memo f = (map f [0..] !!)
The example works fine until I modify it as follows:
memo :: (Int -> a) -> (Int -> a)
memo f = (\x -> (map f [0..] !!) x)
I would have expected this to be a no-op, but it unexpectedly destroys performance.
Thank you!