Recovering from stack overflow or heap exhaustion in a Haskell program

后端 未结 4 2199
情深已故
情深已故 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:25

    It seems to me like the best solution would be to tell the program: 
    "Hey, try doing this, but if you fail don't worry. I know how to handle it"
    

    In most languages that would be a try/catch block. I'm not sure what the equivalent is in haskell, or even if some equivalent exists. Furthermore, I doubt that a try/catch construct could effectively trap/handle a stack overflow condition.

    But would it be possible to apply some reasonable constraints to prevent the overflow from occurring? For instance, perhaps you could set some upper-bound on the size of a system, and monitor how each system approaches the boundary from one iteration to the next. Then you could enforce a rule like "if on a single evolution a system either exceeded its upper-bound or consumed more than 50% of the space remaining between its previous allocation and its upper-bound, that system is terminated and suffers a score penalty".

提交回复
热议问题