[Haskell-cafe] Re: What causes <<loop>>?

Apfelmus, Heinrich apfelmus at quantentunnel.de
Wed Dec 3 05:04:36 EST 2008


Martin Hofmann wrote:
> Thunks with reference on themselves was mentioned as main reason for
> <<loop>>.
> 
>> A safe recursive definition would be
>>   let x = Foo (x+1)
>> However, if you leave out the constructor,
>>   let x = x + 1
>> you get a <<loop>> (or a deadlock).
>>
> 
> Are there any other reasons? 

A program that exits with <<loop>> is basically a program that runs
forever. Examples of programs that run forever are

  let x = x + 1 in x

  let f x = f x in f 1

In special cases, the run-time system is able to detect that the program
would run forever, and exits with <<loop>> if that happens.

> Sorry, a lot of questions at once, but I am kind of helpless because I
> can't find any reason of my <<loop>>, so any comments, experience, and
> tips are highly appreciated.

Sometimes, a simple cause is accidentally using the same variable name,
i.e. writing

  let (c,s) = foobar s in ...

while you meant

  let (c,s') = foobar s in ...


At other times, non-termination is caused by not using enough
irrefutable patterns. But this usually only happens when writing
algorithms that heavily exploit recursion and laziness, which probably
doesn't apply to your case.


You may want to try the new GHCi debugger, maybe it helps finding the loop.


Regards,
H. Apfelmus



More information about the Haskell-Cafe mailing list