> hold a part of the data in memory while you show the first one,<br><br>Here would be a better example then. <br><br> f lst = show (sum (filter (> 1) lst), sum (filter (> 2) lst))<br><br>It ought to be *possible* to compute both operations without holding onto any of the list elements.
<br><br>In the imperative world, you'd say:<br> sum1 = 0<br> sum2 = 0<br> for num in lst<br> sum1 += num if num > 1<br> sum2 += num if num > 2<br> end<br> puts sum1, sum2<br><br>One could probably hack it together with foldM, the State monad, and maybe some strictness, but I'd like to make full use of laziness and stick to the basic list operations if it at all possible.
<br><br>I'm not so concerned with solving this particular problem as I am in learning the purely functional technique for performing orthogonal computations on the same input without introducing a space leak.<br><br>Maybe something like this?
<br> arr (sum . filter (>1)) &&& arr (sum . filter (>2))<br><br>Thanks,<br>Greg<br><br>