Debugging 调试/检查函数内的值

Debugging 调试/检查函数内的值,debugging,haskell,ghc,ghci,Debugging,Haskell,Ghc,Ghci,考虑以下人为的例子: module Main where myadd3 first second third = let result1 = first -- line 3 result2 = second -- line 4 result3 = third -- line 5 in result1 + result2 + result3 -- line 6 我想在到达第6

考虑以下人为的例子:

module Main where
myadd3 first second third = 
  let result1 = first               -- line 3
      result2 = second              -- line 4
      result3 = third               -- line 5
  in result1 + result2 + result3    -- line 6
我想在到达第6行时检查
result1
result2
result3
的值。然而,当我一步一步地浏览代码时,这些“计算”中的任何一个似乎都不可供检查:

*Main> :break 3
Breakpoint 0 activated at Main4.hs:3:17-21
*Main> :break 4
Breakpoint 1 activated at Main4.hs:4:17-22
*Main> :break 5
Breakpoint 2 activated at Main4.hs:5:17-21
*Main> :break 6
Breakpoint 3 activated at Main4.hs:6:6-32
*Main> myadd3 2 3 4
Stopped at Main4.hs:6:6-32
_result :: a = _
result1 :: a = _
result2 :: a = _
result3 :: a = _
[Main4.hs:6:6-32] *Main> :step
Stopped at Main4.hs:6:6-22
_result :: a = _
result1 :: a = _
result2 :: a = _
[Main4.hs:6:6-22] *Main> :step
Stopped at Main4.hs:3:17-21
_result :: Integer = _
first :: Integer = 2
[Main4.hs:3:17-21] *Main> :step
Stopped at Main4.hs:4:17-22
_result :: Integer = _
second :: Integer = 3
[Main4.hs:4:17-22] *Main> :step
Stopped at Main4.hs:5:17-21
_result :: Integer = _
third :: Integer = 4
[Main4.hs:5:17-21] *Main> :step
9

也就是说,我们有类似于
result1::a=\ucode>的行,但没有类似于
result1::a=2的行。这是因为haskell的懒惰本性吗?如果是,那么在值绑定到它们的时候,有没有办法检查
result1
result2
、和
result3
?谢谢

你是对的,这种行为是由于懒惰造成的。要强制评估,您可以执行以下操作:

[debug.hs:6:6-32] *Main> :print result1
result1 = (_t1::a)
[debug.hs:6:6-32] *Main> :force result1
*** Ignoring breakpoint
result1 = 2
[debug.hs:6:6-32] *Main> :step
Stopped at debug.hs:6:6-22
_result :: Integer = _
result1 :: Integer = 2
result2 :: Integer = _