GHC lets you exercise rudimentary control over the messages printed when the runtime system "blows up," e.g., on stack overflow.
Simply write some of the following procedures in C and then make sure they get linked in, in preference to those in the RTS library:
For example, here is the "hooks" code used by GHC itself:
#include <stdio.h> #define W_ unsigned long int #define I_ long int void ErrorHdrHook (where) FILE *where; { fprintf(where, "\n"); /* no "Fail: " */ } void OutOfHeapHook (request_size, heap_size) W_ request_size; /* in bytes */ W_ heap_size; /* in bytes */ { fprintf(stderr, "GHC's heap exhausted;\nwhile trying to allocate %lu bytes in a %lu-byte heap;\nuse the `-H<size>' option to increase the total heap size.\n", request_size, heap_size); } void StackOverflowHook (stack_size) I_ stack_size; /* in bytes */ { fprintf(stderr, "GHC stack-space overflow: current size %ld bytes.\nUse the `-K<size>' option to increase it.\n", stack_size); } void PatErrorHdrHook (where) FILE *where; { fprintf(where, "\n*** Pattern-matching error within GHC!\n\n This is a compiler bug; please report it to glasgow-haskell-bugs@dcs.glasgow.ac.uk.\n\nFail: "); } void PreTraceHook (where) FILE *where; { fprintf(where, "\n"); /* not "Trace On" */ } void PostTraceHook (where) FILE *where; { fprintf(where, "\n"); /* not "Trace Off" */ }