Román García
Román García

Reputation: 425

Windows IDE for Haskell

I need to setup a simple and compelling dev environment for small proyects written in Haskell in Windows machines for freshmen.

I have tried several ways to integrate Haskell into VSCode in Windows with no success.

I had a nice setup a few years ago, but I´m finding problems with dependencies recreating that environment:

It seems that the "cool" way right now is Language Server Protocol + VScode. ghc-mod seems not to be mantained anymore, Intero has reached EOL, HEI is merging with another project... Having a stable and updated dev environment looks like a moving target.

So, the question is: does anyone have reproducible step-by-step instructions for having VSCode working with Haskell in Windows?

I will test any suggestion in a fresh Windows 10 64bits VM and report the results.

Note: VSCode + Docker container is not an option. Most of the student´s machines have 4GB RAM.

Thanks in advance.

Upvotes: 4

Views: 1511

Answers (1)

danidiaz
danidiaz

Reputation: 27771

There's a tool called ghcid (not to be confused with ghcide) that, while nowhere near a full-blown IDE, is pretty robust and provides some niceties like re-compiling on save and showing compile errors. It doesn't support go-to-definition though. It has a VSCode plugin.

Here's a possible way of setting up things in Windows:

  • Download the GHC 8.8.3 binaries for Windows from here.
  • Download the cabal-install 3.0.0.0 binaries for Windows from here.
  • Decompress them in some folder.
  • Add entries to your PATH environment variable so that it has access to the /bin folder of the GHC installation and to the folder containing the cabal executable.
  • Open a Powershell console.
  • Run cabal udpate
  • Run cabal install --install-method=copy --installdir=somefolder ghcid to install the ghcid executable, where "somefolder" is the destination folder. (If the installation fails, try running the command from a Git Bash or Cygwin terminal as a workaround.) Put the destination folder in PATH.

  • Open (or restart) VSCode and install the "Haskell Syntax Highlighting" and haskell-ghcid plugins.

  • Go to an example cabal project, use the Ctrl-Shift-P shortcut, and execute the Start ghcid action. The ghcid terminal will appear.

Example of a ghcid session showing an error:

enter image description here

The haskell-ghcid plugin can read a .ghcid file in the project root containing flags that should be passed to the ghcid command.


Extra instructions to set up code formatting:

  • Install the ormulu formatter by running cabal install ormolu --install-method=copy --installdir=somefolder. Again, make sure that the destination folder in in PATH.

  • Open (or restart) VSCode and install the ormulu plugin.

Now the "Format Document" and "Format Selection" actions in VSCode will use ormulu.


Another way of installing GHC and getting to ghcid and ormulu could be by using the stack tool, which handles GHC installation by itself.

Upvotes: 3

Related Questions