Skip to content

Instantly share code, notes, and snippets.

@ezyang
Last active November 17, 2016 00:00
Show Gist options
  • Save ezyang/ce2767f92ba2c90b7ea53eff5c3965a8 to your computer and use it in GitHub Desktop.
Save ezyang/ce2767f92ba2c90b7ea53eff5c3965a8 to your computer and use it in GitHub Desktop.
Haskell on Windows for Linux refugees

Haskell on Windows

These are empirical observations about running Haskell on Windows. If your experiences have been different, I'd love to hear about it.

Install

You'll need to get the

These days, I like using chocolatey to set things up, because you can use it to manage other packages as well.

Pick a console

A very common way of working with GHC is via the command line, and as a Linux refugee, you will tend to expect such amenities as Ctrl-C and Ctrl-Z to work correctly when you are editing files. Unfortunately, every choice has its own idiosyncracies.

  • cmd.exe or PowerShell. You'll get the best native experience with these, including totally working Ctrl-C on GHCi, but they'll be Windows style terminals, so you'll have to deal with the idiosyncracies of working within not-Bash. If all you're doing is going straight to the GHCi prompt, this can be fine.
  • Use cmd.exe to call MSYS2 bash is another way to get into a "nice" environment. The good things: GHCi will work correctly; it will interrupt computations with Ctrl-C which is good. The downside is that process control works is fairly inconsistent. For example, it is not possible to suspend (Ctrl-Z) GHCi and many other executables (e.g., sleep). Mercifully, vim DOES work with process control. Additionally, Ctrl-C will fail to work in some situations. One particular situation I know of is if you are running a Haskell process which in turn is waiting on another process; Ctrl-C does not seem to work in this situation (it does work if you were using cmd.exe directly!)
  • MSYS2 Shell (mintty-based). DON'T USE THIS. You get this shell if you install msys2 (http://msys2.github.io), which is standard operating procedure if you are, e.g., building GHC from scratch. The big problem is that GHCi will not work at all, and process control will be bad. For example (this is using chocolatey installed GHC with a stock MSYS2 installation):
    • If you run ghci, and then Ctrl-C, your bash will freeze up. If you open Task Explorer, you will see that ghc.exe is still running; if you kill it you'll get back control of your terminal. This is a very old bug (and you'll see a warning about it when you run GHCi) with a workaround (4d57994585c858a7be242c8db23a3e40834dfc72) from 2005. The proximal problem is that when you type Ctrl-c in this shell, mintty will call TerminateProcess to kill the process, which prevents it from cleaning up and killing the ghc.exe subprocess that it spawned. This problem affects many other projects, see for example https://sourceforge.net/p/msys2/tickets/135/ and mintty/mintty#485 ; this will also affect you if you run Haskell executables which spawn subprocesses; if you Ctrl-C them the subprocesses will stick around.
    • If you try ghcii.sh, Ctrl-C will no longer cause bash to freeze up, but it will still exit GHCi, which is probably not what you want.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment