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.*
Background
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 hello.hs
file
$ 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.hi
and hello.o
, which are just intermediate compilation files. You can check the hello binary using theĀ file
tool:
$ 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 š
Ā
0 comments