使用GHCi调试Haskell程序中的无限循环 [英] Debugging infinite loops in Haskell programs with GHCi

查看:219
本文介绍了使用GHCi调试Haskell程序中的无限循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个Haskell程序中第一次遇到无限循环。我把它缩小到一个相当特定的代码段,但我似乎无法准确地确定我有一个非终止的递归定义。我很模糊:跟踪和:GHCi中的历史,但问题是我的代码的一些分支涉及到一个 Data.Map.Map x 是通过调整获取地图中的东西 x根据 x'根据其他地图中的值,确定'。具体细节在这里并不重要,但是正如你可能会告诉的,如果这是以交织的递归方式发生的话,我的电话历史就会在map c> lookup s,调整 ments和插入离子。

For the first time I've encountered an infinite loop in a Haskell program I'm writing. I've narrowed it down to a quite specific section of code, but I cannot seem to pinpoint exactly where I have a non-terminating recursive definition. I'm vaguely familiar with :trace and :history in GHCi, but the problem is that some branches of my code involve quite a bit of recursive modifications of a Data.Map.Map in the sense that the map x is obtained by adjusting something in the map x' based on values in another map depending on x'. The specifics don't matter here, but as you can probably tell, if this happens in an intertwined recursive way, my call history gets completely bogged down in all the various comparisons involved in map lookups, adjustments and insertions.

任何人都可以推荐一种更有效的方法来定位无限循环?例如,这将有助于将通话记录限制在来自单个源文件的呼叫中。

Can anyone recommend a more efficient way to locate infinite loops? It would, for example, help a lot to restrict the call history to calls from a single source file.

推荐答案

确保你我们已经使用了GHCi调试器,包括设置-fake-on-exception(如果你正在获得<< loop>> ?),并确保您已经尝试了Stephen使用GHC警告的建议。

Be sure you've used the GHCi debugger to it's full extent, including setting -fbreak-on-exception (useful if you're getting <<loop>>, are you?) and be sure you've tried Stephen's advice of using GHC's warnings.

如果这些失败(GHCi调试器真的不应该失败,那只是一个问题解释数据),然后尝试在循环的情况下运行 HPC ,以便您可以直观地查看分支机构和没有评估的值,如果循环,那么应该做的事情可能甚至没有被评估,并且会显示在标记的HTML中。

If these fail (GHCi debugger really shouldn't 'fail', it's just a matter of interpreting the data) then try to run HPC on the looping case so you can visually see branches and values that aren't being evaluated, if it's looping then something that should be getting done probably isn't even being evaluated and that will show up in the marked up HTML.

这篇关于使用GHCi调试Haskell程序中的无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆