4

I installed Haskell on Windows with these commands:

  1. Set-ExecutionPolicy Bypass -Scope Process -Force; 
    [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;
    iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
    
  2. choco install haskell-dev
    

After install successfully I write the code on VSCode and try to run the code with the help of code runner it gives me this error:

'runhaskell' is not recognized as an internal or external command, operable program or batch file.

How to solve this problem ?

hussamsindhu
  • 101
  • 1
  • 8

2 Answers2

6

ghc --version 9.0.1 did not have runhaskell.If you want to run your code in vs code through coderunner than go into vs code setting->coderunner->setting.jason in "code-runner.executorMap" write "runghc" instead of "runhaskell" like "code-runner.executorMap": {"haskell": "runghc",}

hussamsindhu
  • 101
  • 1
  • 8
6

Hussmansindu was right with his response. Although the setup in VSCode may sound confusing, You would be able to run Haskell code in VSCode when running it with the "ghc" base.

VSCode default set up for running it was "runhaskell," whereas you need "runghc." To do so, please follow the following approach step-by-step.

In VSCode, while on any file you want to run:

  1. Use your keyboard and press "Ctrl ," ( press the control key and the comma key simultaneously). By doing so, you are about to access the setting page.

  2. You have prompted the setting page to open and will see something like this image below: Valid XHTML.

  3. In the search setting field as depicted in the image please, enter the keyword "code runner" as shown below and locate the "code-runner: Executor Map By File Extension" as illustrated in the image, then click the Edit in settings.json link Valid XHTML.

  4. Then, the setting page will be prompted and as depicted below. Locate the line "haskell": "runhaskell" and change it to "haskell": "runghc" as shown in the snap below Valid XHTML.

  5. Press Ctrl S to save the setting and close the window.

  6. Now, try to run the Haskell file.

I hope my explanation helps.

Many regards.

Ola

Ola_leke
  • 61
  • 1
  • 6
  • but what if my Settings.json is empty? I followed ur steps – Schesam Oct 13 '21 at 09:32
  • Hello Schesam, Have you ever run any code in VSCode IDE? If yes, it is hard to imagine that your code runner settings.json @ Executer Map is empty. However, I think you should look at this thread [link](https://code.visualstudio.com/docs/getstarted/settings#_creating-user-and-workspace-settings) for full documentation on how to config User & Workspace Settings. I believe, however, that you need a reset of your code runner Settings.json @ Executor Map. This thread [here](https://www.codegrepper.com/code-examples/whatever/vs+code+reset+code+runner+settings) may be helpful. Many regards. Ola – Ola_leke Oct 20 '21 at 10:38
  • Hello @Schesam. You can simply add the following entry in your user settings file (i.e. `%APPDATA%\Code\User\settings.json` for Windows): `"code-runner.executorMap": { "haskell": "runghc" },` – Gabriel Anton Nov 20 '21 at 16:40