Here is the problem: sometimes, when playing with GHCI, I end up running an infinite computation by mistake. When this happens, most times, my computer crashes and I'm not even able to interrupt it using Ctrl+C. I wonder if there is a way to run GHCI (or another interactive console like Hugs) in some mode that allows me to interrupt the program before the memory runs out. Maybe setting a virtual limit for the recursion depth or for the memory used.
(This question may be a duplicated of Is there a way to limit the memory, ghci can have? but this also considers the posibility of a recursion depth limit, not just memory limit.)
You can try using the RTS options to control the garbage collector when starting GHCi. For instance,
ghci +RTS -M100M -RTS Foo.hs
should limit the memory to 100MB. Alternatively, use -Ksize
to limit the stack (by default it is limited by 80% of the heap).