Recovering from stack overflow or heap exhaustion in a Haskell program

后端 未结 4 2200
情深已故
情深已故 2021-02-10 04:50

I am currently writting a genetic algorithm in Haskell in which my chromosomes are rather complex structures representing executable systems.

In order for me to evaluate

4条回答
  •  情话喂你
    2021-02-10 05:39

    I think a general solution here is to provide a way to measure computation time, and kill it if it takes too much time. You can simply add counter to your evaluation function if it's recursive and if it drops to zero you return an error value - for example Nothing, otherwise it's Just result.

    This approach can be implemented in other ways than explicit count parameter, for example by putting this counter into monad used by evaluation (if your code is monadic) or, impurely, by running computation in separate thread that will be killed on timeout.

    I would rather use any pure solution, since it would be more reliable.

提交回复
热议问题