查看 Haskell 中的缩减步骤
有没有办法查看haskell中的减少步骤,即跟踪所做的递归函数调用? 例如,chez 方案为我们提供了trace-lambda。 Haskell 中有等效的形式吗?
Is there any way to view the reduction steps in haskell, i.e trace the recursive function calls made? For example, chez scheme provides us with trace-lambda. Is there an equivalent form in Haskell?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以尝试插入
Debug.Trace.trace
在你想要跟踪的地方,但这有(a)产生严重无序输出的趋势,因为你的跟踪语句可能属于一个不是“的thunk” t 评估直到远离原始调用,并且 (b) 更改程序的运行时行为,如果跟踪需要评估本来不会评估的事物(尚未)。这是为了调试吗? 如果是这样...
Hat 修改您的源代码以输出跟踪,可以在运行后查看。 输出应该非常接近你想要的:他们主页上的示例是
现在,GHCi (≥6.8.1) 还附带了一个调试器:
虽然不是那么好,但它的优点是易于使用,并且无需重新编译代码即可使用。
You could try inserting
Debug.Trace.trace
in places you want to trace, but this has the tendency of (a) producing wildly out-of-order output, as your trace statement may belong to a thunk that isn't evaluated until far far away from the original call, and (b) changing the runtime behavior of your program, if tracing requires evaluating things that wouldn't otherwise have been evaluated (yet).Is this for debugging? If so...
Hat modifies your source code to output tracing which can be viewed after running. The output should be pretty close to what you want: the example on their homepage is
These days, GHCi (≥6.8.1) also comes with a debugger:
While not as nice, it has the benefit of being easily available, and being usable without recompiling your code.
拥抱次数减少了,有帮助吗?
或者,您可以使用类似“hugs hood”之类的东西来包装您的代码,以获取有关它在每个步骤中执行的操作的更多详细信息吗?
There's a reduction count in hugs, if that helps?
Alternatively, could you use something like the hugs hood to wrap your code, to get more detail around what it's doing at each step?
Haskell 标准中没有内置任何此类内容。
我希望 Helium 图形解释器能够提供类似的东西但网页上对此主题只字未提。
Nothing of the kind is built into the Haskell standard.
I would hope that the Helium graphical interpreter would offer something like this, but the web page is silent on the topic.
部分解决方案是使用 vacuum 来可视化数据结构。
我看过一些折叠、扫描等的gif动画,但目前找不到。 我认为动画是凯尔·吉巴德制作的。
A partial solution is to use vacuum to visualize data structures.
I've seen some gif animations of fold, scan and others, but I can't find them at the moment. I think Cale Gibbard made the animations.