Debugging 将where子句引入GHCi调试器的作用域

Debugging 将where子句引入GHCi调试器的作用域,debugging,haskell,ghci,Debugging,Haskell,Ghci,今天早些时候,我试图调试下面的solve函数的一个版本,该函数给我带来了一些问题: newtype Audience = Audience { byShyness :: [Int] } solve :: Audience -> Int solve (Audience originalCounts) = numFriendsAdded where numFriendsAdded = length $ filter id friendAdded friendAdded

今天早些时候,我试图调试下面的
solve
函数的一个版本,该函数给我带来了一些问题:

newtype Audience = Audience { byShyness :: [Int] }

solve :: Audience -> Int
solve (Audience originalCounts) = numFriendsAdded
  where numFriendsAdded = length $ filter id friendAdded
        friendAdded     = zipWith3 (\i c t -> i >= c + t) [0..] originalCounts alreadyStanding
        alreadyStanding = scanl (+) 0 modifiedCounts
        modifiedCounts  = zipWith (\a c -> if a then 1 else c) friendAdded originalCounts
在GHCi(7.8.2)中,我试图先按名称,然后按行/列突破
solve
,但似乎没有将
where
子句中绑定的名称纳入范围:

λ :b solve 
Breakpoint 0 activated at StandingOvation.hs:(20,1)-(24,89)
λ :main StandingOvation.example-input 
Case #1: Stopped at StandingOvation.hs:(20,1)-(24,89)
_result :: Int = _
λ numFriendsAdded
<interactive>:5:1: Not in scope: ‘numFriendsAdded’
λ :delete 0
λ :b 20 35
Breakpoint 1 activated at StandingOvation.hs:20:35-49
λ :main StandingOvation.example-input 
Case #1: Stopped at StandingOvation.hs:20:35-49
_result :: Int = _
numFriendsAdded :: Int = _
λ numFriendsAdded                                                                                                     
0
λ friendAdded
<interactive>:10:1: Not in scope: ‘friendAdded’
λ:b解算
断点0在StandingOvation.hs时激活:(20,1)-(24,89)
λ:主要标准。示例输入
案例#1:停在停机位。hs:(20,1)-(24,89)
_结果::Int=_
λnumFriendsAdded
:5:1:不在范围内:“numFriendsAdded”
λ:删除0
λ:b2035
断点1在待机状态下激活。hs:20:35-49
λ:主要标准。示例输入
案例#1:停在停机位。hs:20:35-49
_结果::Int=_
numFriendsAdded::Int=_
λnumFriendsAdded
0
λ
:10:1:不在范围内:“friendAdded”

显然,就Haskell而言,它们是相互作用域,但在调试时我需要做什么才能使它们可见?

不幸的是,GHCi调试器不能在断点处使作用域中的所有内容都可用。引用(7.8.2和7.10.1(最新版本)中的文本相同):

GHCi为断点所在表达式的自由变量[6]提供了绑定(
a
),另外还为表达式的结果提供了绑定(
\u result
)。[……]

脚注:

[6] 我们最初为作用域中的所有变量提供绑定,而不仅仅是表达式的自由变量,但发现这大大影响了性能,因此当前仅对自由变量进行了限制

本质上,只有在表达式GHCi当前停止时直接提到局部变量,才能看到它们。这让我想到了一个解决办法,虽然很傻,但确实有效。将函数的主线替换为:

solve (Audience originalCounts) =
    (friendAdded,alreadyStanding,modifiedCounts) `seq` numFriendsAdded

现在,表达式中提到了您感兴趣的所有变量,因此您可以停下来查看它们。

啊,好的,这就解释了。起初我以为是
那里
,但现在我发现我甚至看不到
原始帐户
,考虑到你的解释,这是有道理的。