GHCi - 第二次运行时跳过断点

发布于 2024-12-29 19:11:04 字数 265 浏览 1 评论 0原文

我是 Haskell 的新手,在调试时遇到了令人讨厌的行为。

  1. 我使用 :break 添加断点
  2. 我运行 main
  3. 一切正常
  4. 我输入 :continue 完成执行

当我重新运行 main 时,断点不再命中,但断点没有被删除,因为 :show Breaks 列出了它。有人知道发生了什么事吗?

我使用的是 Ubuntu 11.10,64 位。明天我会在不同的环境下测试它。

谢谢

I'm new to Haskell and I'm getting an annoying behaviour when debugging.

  1. I add my break point using :break
  2. I run main
  3. Everything is ok
  4. I type :continue to finish the execution

When I rerun main, the breakpoint does not hit anymore but the breakpoint wasn't removed because :show breaks lists it. Anyone knows what's going on?

I'm on Ubuntu 11.10, 64 bits. I'll test it on a different environment tomorrow.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最丧也最甜 2025-01-05 19:11:04

如果不看代码就很难知道,但听起来很可能在第二次运行 main 时永远不会到达断点,因为结果由于惰性求值而被缓存。第一次可能是 THUNK(暂停评估),第二次已经评估了。

It's hard to know without seeing the code, but it sounds likely that on the second run of main the breakpoint is never reached because the result is cached because of lazy evaluation. It probably was a THUNK (a suspended evaluation) first time, and the second time it is already evaluated.

带上头具痛哭 2025-01-05 19:11:04

为了避免重新计算,常量应用程序表单被替换为对其 redex 的间接引用。

例如,在下面的代码片段中,“papperlap”的右侧将被替换为指向“4”的间接节点。

bla x = x + 1
papperlap = bla 3

如果您在“bla”上设置断点并请求“paperlap”两次,您将看到“bla”仅应用一次。但如果你两次请求“bla 3”,我们也会停止两次:

*Main> :break bla
Breakpoint 0 activated at meerbla.hs:1:1-13
*Main> papperlap
Stopped at meerbla.hs:1:1-13
_result :: a = _
[meerbla.hs:1:1-13] *Main> :continue
4
*Main> papperlap
4
*Main> bla 3
Stopped at meerbla.hs:1:1-13
_result :: a = _
[meerbla.hs:1:1-13] *Main> :continue
4
*Main> bla 3
Stopped at meerbla.hs:1:1-13
_result :: a = _
[meerbla.hs:1:1-13] *Main> :continue
4

To avoid recomputations constant application forms are replaced with an indirection to its redex.

For example the following snippet the right hand side of 'papperlap' will be replaced with an indirection node pointing to '4'.

bla x = x + 1
papperlap = bla 3

If you set a breakpoint on 'bla' and ask for 'papperlap' twice you will see that 'bla' is applied only once. But if you ask for 'bla 3' twice, we will also stop twice:

*Main> :break bla
Breakpoint 0 activated at meerbla.hs:1:1-13
*Main> papperlap
Stopped at meerbla.hs:1:1-13
_result :: a = _
[meerbla.hs:1:1-13] *Main> :continue
4
*Main> papperlap
4
*Main> bla 3
Stopped at meerbla.hs:1:1-13
_result :: a = _
[meerbla.hs:1:1-13] *Main> :continue
4
*Main> bla 3
Stopped at meerbla.hs:1:1-13
_result :: a = _
[meerbla.hs:1:1-13] *Main> :continue
4
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文