3

Say I had the following code in Haskell:

x :: Int
y :: Int
z :: Int
x=y
y=z
z=x

Naturally, referring to any of these variables causes execution to bomb with <<loop>> if using ghc or spin infinitely if using ghci. I'm working on some code that has high potential for circularity if miscoded - is there any way to debug <<loop>> - can I examine the stack when it bombs to see the circularity?

1

1 Answer 1

2

I looked at the question @TheInternet linked, and the first answer's advice to use -fbreak-on-exception-fbreak-on-error and :trace is pretty good. However I thought I'd mention two small snags I hit that are specific to this question:

  1. GHCi does not make <<loop>> exceptions, only native compiled GHC does that, and the GHCi debugger cannot trace native compiled code.

Fortunately, this can be solved by pressing ^C to interrupt manually.

  1. Trying to :trace and then ^C manually instead does give a debugger session, but GHCi hasn't inserted any breakpoints and so there's no context to debug!

This was also easy to fix: I just changed the first equation to x = id y. This is enough to get GHCi to insert breakpoints. I suspect that this problem was due to the OP's code cycle containing only trivial variable equations (to quote the GHC User's Guide: "Single variables are typically not considered to be breakpoint locations (unless the variable is the right-hand-side of a function definition, lambda, or case alternative)"), and that it will not usually happen in "real" code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.