Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 680
user5783821 Avatar asked Apr 21 '18 18:04

user5783821


People also ask

How do I debug a haskell program?

Debugging. To debug the main function of a file, press cmd-shift-p (Mac) or ctrl-shift-p (Linux/Windows) to launch the command palette, type in haskell debug and press enter.

Does VS code support haskell?

Haskell for Visual Studio Code. This extension adds language support for Haskell, powered by the Haskell Language Server. As almost all features are provided by the server you might find interesting read its documentation.

How do I run haskell in Visual Studio?

Features. Press command + shift + P to: Load GHCi(or Stack/Cabal repl) with current file: Load GHCi. Run current Haskell file: Run Haskell File.


1 Answers

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;

like image 197
user3335966 Avatar answered Oct 25 '22 13:10

user3335966