title: When is memoization automatic in GHC Haskell?
body: <p>I can't figure out why m1 is apparently memoized while m2 is not in the following:</p>
  
  <pre><code>m1      = ((filter odd [1..]) !!)
  
  m2 n    = ((filter odd [1..]) !! n)
  </code></pre>
  
  <p>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.</p>