Bringing the where clause to the scope in the GHCi debugger

Earlier today, I tried to debug the version below solve , which was giving me problems:

 newtype Audience = Audience { byShyness :: [Int] } solve :: Audience -> Int solve (Audience originalCounts) = numFriendsAdded where numFriendsAdded = length $ filter id friendAdded friendAdded = zipWith3 (\ict -> i >= c + t) [0..] originalCounts alreadyStanding alreadyStanding = scanl (+) 0 modifiedCounts modifiedCounts = zipWith (\ac -> if a then 1 else c) friendAdded originalCounts 

In GHCi (7.8.2), I tried to break solve by name and then row / column, but it did not bring the names associated with the where clause into scope:

 λ :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' 

Obviously they are in a separate scope with regard to Haskell, but what do I need to do to make them visible when debugging?

+5
source share
1 answer

Unfortunately, the GHCi debugger does not make everything available at the breakpoint. To quote from the user manual (the text is identical in 7.8.2 and 7.10.1 (last)):

GHCi provided bindings for free variables [6] of the expression on which a breakpoint ( a , left , right ) was set, and additionally a binding for the result of the expression ( _result ). [...]

and footnote:

[6] We initially provided bindings for all variables in the scope, and not just for free variables of the expression, but found that this significantly affected performance, therefore, limiting the restriction to only free variables.

Essentially, you can only see local variables if they are mentioned directly in the GHCi expression that is currently stopped. This makes me think of a workaround that, although pretty dumb, works. Replace the main line of the function:

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

Now all the variables that interest you are mentioned in the expression, so you can dwell on it to see them all.

+4
source

All Articles