Limiting resources on a per-function basis?
baueran at t-online.de
Fri Jan 2 16:13:58 EST 2004
On Fri, Jan 02, 2004 at 10:07:05PM +1000, Jeff Newbern wrote:
> I would really like to be able to set resource limits on a per-function
> basis. I am envisioning something like:
> limit :: l -> (a -> b) -> (a -> Maybe b)
> limit lim fn = ...
> which would convert a function so that it returns Nothing if a limit
> (on stack, heap, time, etc.) is exceeded during evaluation of that
> function. Is there any hope of being able to do this within the
> existing GHC libraries?
I am by no means a Haskell expert myself, but I did look into this
issue for some time as well...
If this was possible (say, with respect to time), then the compiler
would be able to determine whether your functions terminate, or not.
This, however, is rarely ever possible. Also, space consumption is
hard to predict in face of general recursive structures, because you
don't know how deep down the call sequence your function has to go.
Sure, you could constrain your recursions, e.g. to tail recursion
only, but for the general case, the answer for your question would be
"no, it's not possible".
There are, however, many approaches to overcome (or, at least address)
these sorts of problems in functional programming. For instance, look
at www.hume-lang.org, or look at synchronous dataflow languages which
incorporate aspects of functional programming (e.g. Lucid Synchrone).
I think, this field is pretty much a research area at the moment, but
very much worth dealing with. Corrections to the above, however, are
more than welcome.
(o_ Andreas Bauer, baueran at in.tum.de, http://home.in.tum.de/baueran/
//\ "I have made this letter longer than usual because I lack the time
V_/_ to make it shorter." -- Blaise Pascal
More information about the Haskell-Cafe