Reputation: 4332
Here is a toy function, defined in a file, call it test.hs:
x a b c = do
putStrLn $ show a
return a
One can of course import it into GHCI and set a breakpoint:
λ :load test.hs
[1 of 1] Compiling Main ( test.hs, interpreted )
Ok, modules loaded: Main.
λ :break x
Breakpoint 3 activated at test2.hs:(1,1)-(3,12)
λ x 1 2 3
Stopped at test2.hs:(1,1)-(3,12)
_result :: IO b = _
Yet there appears to not be a way to inspect arguments b and c.
Is there any way around this? I am running GHCi 7.8.4.
Upvotes: 3
Views: 236
Reputation: 116139
From the GHC user's guide:
GHCi has provided bindings for the free variables[6] of the expression on which the breakpoint was placed ...
[6] We originally provided bindings for all variables in scope, rather than just the free variables of the expression, but found that this affected performance considerably, hence the current restriction to just the free variables.
Upvotes: 3
Reputation: 4332
I have found a hacky workaround. If one redefines the function x as follows:
x a b c = do
return a; return b; return c;
putStrLn $ show a
return a
Then one must call :step and then b and c can be inspected:
λ :break x
Breakpoint 4 activated at test2.hs:(1,1)-(4,12)
λ x 1 2 3
Stopped at test2.hs:(1,1)-(4,12)
_result :: IO b = _
λ :step
Stopped at test2.hs:(1,11)-(4,12)
_result :: IO Integer = _
a :: Integer = 1
b :: Integer = 2
c :: Integer = 3
It could be nice if there were a way to do this without redefining the function, however.
Upvotes: 2