When is memoization automatic in GHC Haskell?
问题 I can\'t figure out why m1 is apparently memoized while m2 is not in the following: m1 = ((filter odd [1..]) !!) m2 n = ((filter odd [1..]) !! n) m1 10000000 takes about 1.5 seconds on the first call, and a fraction of that on subsequent calls (presumably it caches the list), whereas m2 10000000 always takes the same amount of time (rebuilding the list with each call). Any idea what\'s going on? Are there any rules of thumb as to if and when GHC will memoize a function? Thanks. 回答1: GHC does