Just a quick reply, others might go into more detail.
Let's say I have a function which produces a list of odd integers from 1 to n:f n = filter (odd) [1..n]...and I have another function that makes a list of all sums of pairs of odd numbers from 1 to n:g n = [a + b | a <- (f n), b <- (f n)]I assume that in most languages, (f n) would get called twice (once for a, and once for b), but what happens in Haskell? Does GHC recognize that, since f is a pure function, it only has to be evaluated once for a given n?
If not, would a 'where clause' make any difference? e.g.,g n = [a + b | a <- h, b <- h] where h = f n