I wanted to try out Haskell on Windows 10 and figured I’d probably use Visual Code for writing code, here’s the steps to get everything installed and configured.
The simplest way to get everything installed seems to be using chocolatey, see Getting Started.
- Install chocolatey
- Run Powershell in admin mode and then run choco install haskell-dev
- Finally, from Powershell run refreshenv
If all of these steps worked, then just run ghc from the Powershell or a command prompt and you should see some output from ghc.
Let’s now set-up Visual Code (I’ll assume you’ve already got Visual Code installed). There’s a few plugins/extensions for Visual Code for use with Haskell. From Visual Code extensions option…
- Add Haskell syntax highlighter
- Also add Haskell-linter
- To configure the linter, from Visual Code select, File | Preferences | Settings, switch to the code view and add the following
"haskell.hlint.executablePath": "C:\\ProgramData\\chocolatey\\lib\\ghc\\tools\\ghc-8.10.1\\bin\\ghc.exe"
Chocolatey installs the files into C:\ProgramData\chocolatey\lib, however if you’ve installed ghc by some other means of within another folder then replace the folder with your location.
Finally, let’s write a Haskell “Hello World”. Within Visual Code create the file HelloWorld.hs and add the following code
main = putStrLn "Hello, world!"
Open the Visual Code integrated terminal or open your preferred terminal/shell and from the folder that you saved your HelloWorld.hs file, run
ghc HelloWorld.hs
If all goes to plan you’ll compile the Haskell file to a HelloWorld.exe and you’re done for now.