I'm working on this tool where the user can define-and-include in [config files | content text-files | etc] their own "templates" (like mustache etc) and these can reference others so they can induce a loop. Just when I was about to create a "max-loops" setting I realized with runghc the program after a while just quits with farewell message of just <<loop>>
. That's actually good enough for me but raises a few ponderations:
how does GHC or the runtime actually detect it's stuck in a loop, and how would it distinguish between a wanted long-running operation and an accidental infinite loop? The halting problem is still a thing last I checked..
any (time or iteration) limits that can be custom-set to the compiler or the runtime?
is this
runghc
-only or does it exist in all final compile outputs?will any
-o
(optimization) flags set much later when building releases disable this apparent built-in loop detection?
All stuff I can figure out the hard way of course, but who knows maybe someone already looked into this in more detail.. (hard to google/ddg for "haskell" "<<loop>>"
because they strip the angle brackets and then show results for "how to loop in Haskell" etc..)
<<loop>>
means that GHC found an expression of the formlet x = x in x
after simplification, and rewrote it tothrow ..
where..
is a special exception which produces the message you see when evaluated - I can't recall what this exception is called, but you may not catch it.<<loop>>
detection is entirely at runtime, and detects any case of a value depending on itself, not just being trivially defined as itself.<<loop>>
whenever, when evaluating a thunk, it finds that it has to evalute the very same thunk to obtain a value. This is more general than what @user2407038 describes. Itis possible to catch many cases of non-termination, the halting problem simply says that we cannot catch all of them.