Lets say I'm given two functions:
f :: [a] -> b
g :: [a] -> c
I want to write a function that is the equivalent of this:
h x = (f x, g x)
But when I do that, for large lists inevitably I run out of memory.
A simple example is the following:
x = [1..100000000::Int]
main = print $ (sum x, product x)
I understand this is the case because the list x
is being stored in memory without being garbage collected. It would be better instead of f
and g
worked on x
in, well, "parallel".
Assuming I can't change f
and g
, nor want to make a separate copy of x
(assume x
is expensive to produce) how can I write h
without running into out of memory issues?