I've recently received a couple of questions asking when Haskell support would be added to WSL, and was surprised since I thought Bash/WSL users were aware of the fact that Haskell has been working for the last few weeks, ever since #14986 in fact, but it appears that we'd not explicitly communicated the fact, so ... here we are! 🙂
Haskell now runs in Bash on Windows!*
* You'll need to be running Windows 10 Insider build #14986 or later.
Haskell is a popular and powerful functional programming language which wasn't able to run on Bash/WSL in Anniversary Update or earlier Insider builds, because WSL had not yet implemented the
timer_create() syscall. Now that WSL builds >= #14986 do support timer_create() we can run Haskell and many other tools (e.g. Elm, Cabal, Pandoc, Agda, etc.) 🙂
Note: You can, as with most modern dev tools, also run Haskell very happily on Windows, although you may find some packages and add-ons require Linux, which is where the ability to run on Bash/WSL comes in!
Hello World in Haskell
Let's create a Haskell Hello World sample:
First, install the Glasgow Haskell Compiler:
$ sudo apt install ghc
While we could run the Haskell interactive REPL, the GHC compiler can, of course, also compile Linux executables:
Open your favorite Linux editor (mine is Vim) creating a new
$ vim hello.hs
Now enter the following Haskell code:
main = putStrLn "Hello World!"
This declares a
main function whose implementation calls putStrLn that writes "Hello World" to stdout.
After exiting your editor (:wq[Enter] in Vim ;)), compile this file by typing the following:
$ ghc hello.hs -o hello [1 of 1] Compiling Main ( hello.hs, hello.o ) Linking hello ...
This will generate a Linux ELF64 binary file called
hello, along with
hello.o, which are just intermediate compilation files. You can check the hello binary using the
$ file hello hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=0296a5fedb69302e0310bbcb7a8bea8f860a52c5, not stripped
You can now run the binary (note: the ./ prefix is required when executing a local binary):
$ ./hello Hello World!
Congratulations, you're now on your way to being a Haskell guru 🙂