[Haskell-cafe] localized memory management?
will.yager at gmail.com
Wed Jan 20 17:11:01 UTC 2016
The problem is that the semantics of pure languages approximate the behavior of ideal machines (turing machines, lambda machines, etc.). Resource constraints are not first-class features of the language because analyzing resource (time and memory) usage of pure functions is inherently impure.
The ideas you've outlined are pretty much what I would do as well. You can use IO to keep track of time and either IO or a custom pure monad that keeps an approximate memory usage count to keep track of memory.
I'm not sure if you can place memory constraints on forkIO threads, but that would be better than using a separate process.
> On Jan 20, 2016, at 08:53, Johannes Waldmann <johannes.waldmann at htwk-leipzig.de> wrote:
> 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?
> - J.W.
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe