Visual Studio Haskell



I started learning the Haskel programming language and decided to use Visual Studio Code. I installed everything properly haskell and stack and a few haskell extensions in VS. When I create a project and import Lib.hs into Main.hs the compiler throws out errors like it does not recognize the Lib module.

I've tested out the Haskell support of the top mainstream IDEs. Here'sa rundown of the current state of things.

  • Setting up haskell on visual studio code, macos in december 2020. Hi, I am looking forward to learning haskell and using it for my side projects. But the settup is really making me suffer. Is there a link or something on how to setup Visual Studio Code to be haskells IDE.
  • The Glorious Glasgow Haskell Compiler. Haskell If all dependencies to build GHC (with Hadrian) are installed, the Haskell plugin works out of the box. It installs the required Haskell.
  • Hello everyone, In this video we see how to install Haskell in windows and run in visual studio code.Haskell is a general purpose language that can be used.

As a dyed-in-the-wool Emacs hacker I've never used any of the morerecent mainstream IDEs, so I can probably offer an unbiased review ofthe support provided by each.

Note: I tried approaching it as a client would, or prospective Haskelluser, so for any manual intervention I had to do, I've used a tonethat indicates I'm not happy about having to do it, and anything thatdoesn't just work I just discard with little patience, as a realperson would and do today. Even if I know there are probably extramanual investigations that I could do knowing what I do about Haskell,a normal user wouldn't have that advantage.

IntelliJ IDEA

I installed it according to theinstructions on the IntelliJ IDEA web site. Idownloaded it to my Ubuntu laptop and installed it under/opt/intellij.

After installing IntelliJ, running it opens up a splash screen. Ratherthan starting a project, I went straight to the Configure->Pluginsbutton. In the plugins list, I chose IntelliJ-Haskell. After that,it was suggested that I restart, so I hit Restart IDE.

After restarting, on the splash screen I hit Create New Project andchose 'Haskell module'. At this point, it asked me to 'Select thestack binary'. I picked the one at /home/chris/.local/bin/stack, butsomeone else might find it under /usr/local/bin/stack. I hit Next.

Warning: there was a long wait after this step. I entered my projectname and proceeded. Opening the project workspace, it now claims 'busyinstalling hlint', which is a Haskell linting tool. It does this forvarious tools; hlint, hindent, stylish-haskell, hoogle. This tookeasily 15 minutes on my machine. Go make a cup of tea.

Finally, after finishing this process, it's ready to go. Here are somethings that I observed work correctly:

  1. Compile errors when changing code on the fly. Slow, but works. Youcan hit the 'Haskell Problems' tab to see the actual compilermessages.
  2. Hitting Ctrl and mousing over something, which is how you getmetadata in IDEA.
    1. Go to definition of library code.
    2. Go to definition of local code.
    3. Type info at point.
    4. Go to definition of local bindings.

I tested this out by opening the Stack codebase itself. Took about 10seconds on 'Indexing...' and then was ready.

There's a very picky set of steps to opening an existing projectproperly:

  1. You have to go 'Create project from existing source'
  2. Choose 'Create from external model'
  3. Choose the 'Haskell' SDK.

Then it should be good to go. Other ways didn't work for me and I gotstuck.

I've also seen that it's possible to define test and executabletargets quite reasonably.

IntelliJ has support to 'optimize imports' which will remove unneededones, which is very common when refactoring. I'd call that feature amust-have.

Overall, this IDE experience is not bad. As a Haskeller, I could getby if I had to use this.

Visual Studio Code

I followed along with theinstall instructions for Linux. Idownloaded the .deb and ran sudo apt install ./<file>.deb.

I launched Visual Studio Code from the Ubuntu Activities menu. Itdisplays its full UI immediately, which was quite a lot faster thanIntelliJ, which takes about 5 seconds before displaying a UIwindow. Not that I care about start-up times:I use Emacs.

Visual Studio Code: Haskero

I went to the Customize section and then 'Tools and languages'. Uppops a menu for language choices (also quite quickly). I triedinstalling theHaskeroplugin, which, as I understand, is in spirit the same backend andfunctionality of IntelliJ-Haskell. It said 'This extension is enabledglobally'.

Assuming that it was ready to use, I looked for a way to create aproject. I didn't find one, so I opted to try opening an existingHaskell project: stack. I used File -> Open Workspace and chose therepository root directory.

Visual

VSC reports 'Unable to watch for file changes in this largeworkspace.' I followedthe link which had a hint to increase the limit. Iedited my sysctl.conf file as instructed to allow VSC to watch allthe files in my project.

Opening, for example, src/main/Main.hs, it opens quickly, butdoesn't appear to be doing any work like IntelliJ was. So I createsome obvious errors in the file to see whether anything works.

After waiting a while, it seems that I have to save the file to seeany kind of reaction from VSC. So I save the file and wait. I timedit:

After a full minute, I got in the Problems tab the problem.

It seems to be recompiling the whole project on every change. Thispretty much makes this plugin unusable. I don't think the author hastested this on a large project.

In its current state, I would not recommend Haskero. I uninstalled itand decided to look at others.

Visual Studio Code: Haskelly

I decided to try the other similar offering calledHaskelly. After a reload and re-opening Stack, I made an intentionalerror in src/main/Main.hs again and found that nothing happened. NoCPU usage by any process.

There weren't any indicators on the screen of anything failing towork. However, I had an intentional type error in my file that was notflagged up anywhere.

Another plugin that I would rate as not usable. I uninstalled it.

Visual Studio Code: Haskell Language Server

I installed the 'Haskell Language Server', which is supposed to be thelatest state of the art in language backends for Haskell.

Enabling it, I see the message:

hie executable missing, please make sure it is installed, seegithub.com/haskell/haskell-ide-engine.

Apparently I have to manually install something. Okay, sure, why not?

There'sa variety of installation methods. I'mnot sure which one will work. But I already have stack installed, soI try the install from source option:

This seems to clone the whole world and takes a while. Definitely aget a cup of tea moment. After that was done, I went to the directoryand ran this as per the instructions:

I am presented with a myriad of options:

I lookup the GHC version that's being used by the stack source code:

Apparently the GHC version in use by stack is too old. At this point Istop and uninstall the plugin.

Visual Studio Code: ghcid

As a last resort, I tried one more plugin. But nothing seemed tohappen with this one either. So I uninstalled it.

SublimeText

Another popular editor is SublimeText. I installed it via the aptrepositorydocumented here. Idecided to try theSublimeHaskellplugin which seems popular.

Installing things in SublimeHaskell is a little arcane: you first haveto install 'Package Control'. I don't remember which menu item thiswas from. However, SublimeText installs this for you. Once that'sdone, you have to use Tools->Command Pallete, which is a kind ofquick-access tool that's apparently common in SublimeText. In thereyou have to literally type 'package control' and then go to 'PackageControl: Install Package' and hit RET. Then you can typeSublimeHaskell and hit RET. As an Emacs user, I'm not afraid of arcaneUIs.

After installing, it pops up a dialog with:

No usable backends (hsdev, ghc-mod) found in PATH. [..] Please checkor update your SublimeHaskell user settings or install hsdev orghc-mod.

It displays a tab with the README from SublimeHaskell and I assumethis is where SublimeText is done helping me.

Visual

Okay, let's install hsdev!

I had to create a file hsdev.yaml:

Visual Studio For Windows 10 Download

And then run

That took 5 minutes but succeeded. There isn't a 'next button' onSublimeText, so I just restarted it. I did File->Open Folder andopened the stack directory and the Main.hs file.

I see 'Inspecting stack' which indicates that it's actually doingsomething. However, after that finishes, I still don't see any errormessages for my type error. Finally, I make a new change and save thefile, and a little messages area pops up below.

And so one for pretty much every library module in the project.

At this point I can't find a menu or anything else to help meconfigure packages or anything related.

At this point it seems like SublimeText is almost workable. The consappear to be the manual install process, and the complete lack ofguidance in the user experience. I'm afraid I can't recommend this toclients either at the moment.

Summary

The story for Visual Studio Code is pretty dire. I did not find astraight-forward install or reliably working IDE for Haskell in VisualStudio Code, and therefore, at the moment, cannot recommend it to ourclients. Perhaps a little work done on Haskero could bring it up to par.

SublimeText falls over at the finish line. It seems like with a littlework on the user experience could bring this up to par.

IntelliJ IDEA however worked quite well with little to no interventionrequired. So I would indeed recommend it to clients.

Read more aboutHaskell development, tooling and businesson our blog. Email us to setup a freeconsultation with our engineering team to discuss editor options.

Visual Studio Code Haskell Mac

Do you like this blog post and need help with DevOps, Rust or functional programming? Contact us.