Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4536936
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:36:14+00:00 2026-05-21T14:36:14+00:00

I am currently writting a genetic algorithm in Haskell in which my chromosomes are

  • 0

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 the fitness of my chromosomes I have to run an evolution function which performs one computational cycle of a given system. The fitness then is calculated just by counting how many times the evolution can be applied before there is no change in the system (in which case the system terminates).

The problem now is as follows: some systems can run infinitely long and will never terminate – I want to penalise those (by giving them little score). I could simply put a certain limit on number of steps but it does not solve another problem.

Some of my systems perform exponential computation (i.e. even for small values of evloution steps they grow to giant size) and they cause ERROR - Control stack overflow. For human observer it is clear that they will never terminate but the algorithm has no way of knowing so it runs and crushes.

My question is: is it possible to recover from such an error? I would like my algorithm to continue running after encountering this problem and just adjusting the chromosome score accordingly.

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”. However I am not even sure if that’s possible. If not – are there any alternatives?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T14:36:15+00:00Added an answer on May 21, 2026 at 2:36 pm

    This will be hard to do reliably from inside Haskell — though under some conditions GHC will raise exceptions for these conditions. (You will need GHC 7).

    import Control.Exception
    

    If you really just want to catch stack overflows, this is possible, as this example shows:

    > handle (\StackOverflow -> return Nothing) $
                  return . Just $! foldr (+) 0 (replicate (2^25) 1) 
    Nothing
    

    Or catching any async exception (including heap exhaustion):

    > handle (\(e :: AsyncException) -> print e >> return Nothing) $
                  return . Just $! foldr (+) 0 (replicate (2^25) 1) 
    stack overflow
    Nothing
    

    However, this is fragile.

    Alternately, with GHC flags you can enforce maximum stack (or heap) size on a GHC-compiled process, causing it to be killed if it exceeds those limits (GHC appears to have no maximum stack limit these days).

    If you compile your Haskell program with GHC (as is recommended), running it as:

    $ ghc -O --make A.hs -rtsopts 
    

    the low heap limit below is enforced:

    $ ./A +RTS -M1M -K1M
    Heap exhausted;
    

    This requires GHC. (Again, you shouldn’t be using Hugs for this kind of work). Finally, you should ensure your programs don’t use excessive stack in the first place, via profiling in GHC.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently writting a programe about Conway's Game of life and I am
I'm currently writing a TYPO3 extension which is configured with a list of tt_content
I'm currently writing some code for UnconstrainedMelody which has generic methods to do with
Im currently writing my bachelor thesis with latex and using TexnicCenter. I want to
Our company is currently writing a GUI automation testing tool for compact framework applications.
I am currently writing a simple, timer-based mini app in C# that performs an
I am currently writing a small calendar in ASP.Net C#. Currently to produce the
I'm currently writing an ASP.Net app from the UI down. I'm implementing an MVP
I'm currently writing an interface to allow applications to send exception data to a
I'm currently writing a simple .sh script to parse an Exim log file for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.