single-stepping and infinite recursion
mnislaih at gmail.com
Wed Nov 21 06:20:48 EST 2007
you are right, this behaviour is a bit surprising. What you want to
observe can be obtained with, for example:
loop c = putChar c >> loop c
where loop is not a CAF anymore since it takes an argument.
In the definition that you gave, main is a CAF and gets evaluated only
the first time. The subsequent times it is entered do not trigger any
further evaluation: the IO action is already evaluated and the only
thing left to do is execute it. This does not trigger a breakpoint
since no evaluation proper is done.
For more information about CAFs see
That page remarks that CAFs are an optimization which does not alter
referential transparency. Unfortunately their special behaviour is
highlighted by the ghci debugger.
If you want to find the reason for an infinite loop:
1. enable the flag -fbreak-on-error
2. run your expression with :trace (eg :trace loop 'a')
3. hit Ctrl-C while your program is stuck in the loop to have the
debugger break in the loop.
4: use :history and :back to find out where the loop is located and why.
On 20/11/2007, at 16:09, Wolfgang Jeltsch wrote:
> please consider the following program:
> main = putChar 'A' >> main
> I load this into GHCi, enter :step main, followed by :step and a
> second :step.
> Although I would expect to get the As in the output step by step,
> GHCi now
> hangs inside the infinite loop. Is this intentional? To me, this
> rather weird. I wanted to use GHCi’s debugger to find the reason
> for an
> infinite recursion but from my experience it looks as if this might
> not be
> possible. :-(
> Best wishes,
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users at haskell.org
More information about the Glasgow-haskell-users