debugginghaskellghci

Haskell ghci debugger does not display a variable


I'm using Haskell debugger in a Stack project with code like this:

module Lib
    ( someFunc
    ) where

a :: Integer
a = 5

testme :: IO ()
testme = print $ "abc" ++ "def"


someFunc :: IO ()
-- someFunc = putStrLn "someFunc"
someFunc = do
    print a
    testme

I can load modules in debugger like this (running in VSCode terminal):

% stack ghci --with-ghc=ghci-dap --test --no-load --no-build --main-is TARGET

Warning: The following GHC options are incompatible with GHCi and have not been passed to it: -threaded.
         
Configuring GHCi with the following packages: testproj.
[DAP][INFO] start ghci-dap-0.0.25.0.
GHCi, version 9.6.7: https://www.haskell.org/ghc/  :? for help

ghci> :add Main

<no location info>: warning: [GHC-32850] [-Wmissing-home-modules]
    Modules are not listed in options for ‘main’ but needed for compilation:
        Lib
[1 of 3] Compiling Lib              ( /home/example/testproj/src/Lib.hs, interpreted )
[2 of 3] Compiling Main             ( /home/example/testproj/app/Main.hs, interpreted )
Ok, two modules loaded.

ghci> :break someFunc 
Breakpoint 0 activated at /home/example/testproj/src/Lib.hs:(14,12)-(16,10)

ghci> main
Stopped in Lib.someFunc, /home/example/testproj/src/Lib.hs:(14,12)-(16,10)
_result :: IO () = _
[/home/example/testproj/src/Lib.hs:(14,12)-(16,10)] ghci> :print a

<interactive>:1:1: error: Not in scope: ‘a’
[/home/example/testproj/src/Lib.hs:(14,12)-(16,10)] ghci> :step
Stopped in Lib.someFunc, /home/example/testproj/src/Lib.hs:15:5-11
_result :: IO () = _
[/home/example/testproj/src/Lib.hs:15:5-11] ghci> :step
Stopped in Lib.a, /home/example/testproj/src/Lib.hs:6:5
_result :: Integer = _
[/home/example/testproj/src/Lib.hs:6:5] ghci> :print a

<interactive>:1:1: error: Not in scope: ‘a’
[/home/example/testproj/src/Lib.hs:6:5] ghci> :list
5  a :: Integer
6  a = 5
7  
[/home/example/testproj/src/Lib.hs:6:5] ghci> a

<interactive>:15:1: error: [GHC-88464] Variable not in scope: a
[/home/example/testproj/src/Lib.hs:6:5] ghci> :step
5
[/home/mark/haskell/t/testproj/src/Lib.hs:6:5] ghci> :ste
5
Stopped in Lib.testme, /home/mark/haskell/t/testproj/src/Lib.hs:9:10-31
_result :: IO () = _
[/home/mark/haskell/t/testproj/src/Lib.hs:9:10-31] ghci> :step
"Stopped in Lib.testme, /home/mark/haskell/t/testproj/src/Lib.hs:9:18-31
_result :: [Char] = _
[/home/mark/haskell/t/testproj/src/Lib.hs:9:18-31] ghci> :print a

<interactive>:1:1: error: Not in scope: ‘a’

According to this tutorial: https://downloads.haskell.org/ghc/7.4.2/docs/html/users_guide/ghci-debugger.html just typing a name of "variable" should display its value.

How can I display variable values?

Environment:

Stack:     Version 3.5.1, Git revision 5c774d7ca92f4716ef7a51d5da21a5c3713517a5 x86_64 hpack-0.38.0
ghc:       ghc-9.6.7
OS:        Debian Linux

Solution

  • You've only loaded the Main module. You can refer to things in the Lib module with a module prefix, as in Lib.a, or by bringing Lib into scope inside ghci with import Lib or one of its relatives.