[Haskell-cafe] localized memory management?
johannes.waldmann at htwk-leipzig.de
Wed Jan 20 14:53:39 UTC 2016
Dear cafe, how would you approach this task:
find (enumerate) those x from a list xs
for which some computation is not successful
within some resource bound
(it weeds out uninteresting data, leaving just the hard cases,
which will be treated later by other means)
Input and result could be lazy lists, computations are pure.
If the bounded resource is time, then I can use System.Timeout.
This puts me into IO, but OK.
Perhaps I want to do some logging output anyways.
The problem is with bounding space.
Assume that "computation on x" (sometimes) allocates a lot.
Then the whole program will just die with "heap exhausted",
while in fact I want to terminate just the computation on
this x, garbage-collect, and continue.
I could make the space usage explicit:
each step of the computation could additionally
compute a number that approximates memory usage.
(Assume that this usage varies wildly with each step.)
Then I can stop iterating when this reaches some bound.
Or, I just compile the computation into a separate executable,
and I call it (for each x) via the operating system,
because there I can bound space (with ulimit)
Is there some way to achieve this in Haskell land?
More information about the Haskell-Cafe