I have a nonterminating expression in Haskell. I want to debug and inspect the reason why it is not terminating. A technique I learned is to use the following in GHCi:
:set -fbreak-on-exception
:trace nonterminating_expression
^C
:hist 50
So I can see the instructions that are running in the infinite computation. The problem is that I would like to continue the computation with :step
, ignoring the interrupt. Can I do that?
Any other solutions for debugging nonterminating computations? (History larger than 50 records or other practices to help the task.)
One thing I've done in the past is use unsafePerformIO to break whenever I press a key:
Let's say t is your original expression, insert x in the expression:
import System.IO
import System.IO.Unsafe
t i = do print i; t (i+1)
t2 i = do print i; x; t2 (i+1)
x = do r <- hReady stdin
if r then do a<-hGetChar stdin
print a -- break on this line
else print ""
Then at the ghci prompt:
*Main> :break 9
*Main> t2 0
Press a keyboard key
*Main> :cont
resumes where you left off.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With