user5783821
user5783821

Reputation: 329

Debugging haskell in VS Code

I am trying to debug a simple Haskell application in VS Code with the phoityne-vscode plugin. I managed to configure the plugin and run the application - I can see the breakpoints being hit.

The problem is cannot figure out how to interact with the running application. I have a line where I expect user input

do
  someValue <- getLine

Once the debugger reaches this line it stops and I cannot figure out how to pass arguments to the program. I would guess it is somewhere in the Debug Console but it looks like the prompt is only for driving the debugger.

I am sure I am missing something very simple - it's my first attempt at tempering with Haskell and I'm new to VS Code too.

Upvotes: 10

Views: 10059

Answers (1)

user3335966
user3335966

Reputation: 2745

As described in repository - You can't use STD[IN|OUT] methods;
Something like putStrLn will be ignored, but IN methods (getLine for example) just will get stuck;

For functions without STD[IN|OUT] methods You can use F10 - select function and send params (for example [1,2,3] for send list or "str" for send string): enter image description here

With F5 You can run previous configuration or configuration from launch.json:

  • mainArgs - params, that You can get with getArgs (cmd params for your programm);
  • startupFunc - name of the function that will be call first;
  • startupArgs - params for that first function (for example "startupArgs": "666" will the same as <F10> -> 666 -> <Enter>)
  • stopOnEntry - boolean param for enable\disable breakpoint at the start of the function;

Also, if I understood correctly, F10 will rewrite startupFunc and startupArgs;

I'm really new in haskell so I'm confused a little bit when I can get value of constant in debug console, sometimes I have:

[DAP][ERROR] error occurred while runStmt.
Variable not in scope: <...>

Also look like where and let blocks are ignored :D
Use watch panel for better understanding when You can use some constant:

enter image description here

If You want to debug input\output methods You can use ghci debug commands (:h - Commands for debugging block);

For example, You have a program:

89| test :: IO ()
90| test = do
91|   a <- getLine
92|   b <- getLine
93|   putStrLn $ a ++ b

Use :break 93 to add breakpoint at the 93'th line;
Then run your program in interpreter: test;
Enter values. Now You will stop at putStrLn $ a ++ b - if You type a or b in console - You'll get values of these constants;
Then :step for evaluate ++ and :step for putStrLn:

enter image description here

I hope it will be helpful for someone;

Upvotes: 15

Related Questions