{"id":835,"date":"2017-02-09T19:06:03","date_gmt":"2017-02-10T03:06:03","guid":{"rendered":"http:\/\/blogs.msdn.microsoft.com\/commandline\/?p=835"},"modified":"2019-02-25T22:04:23","modified_gmt":"2019-02-26T06:04:23","slug":"haskell-on-bashwsl","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/commandline\/haskell-on-bashwsl\/","title":{"rendered":"Haskell on Bash\/WSL"},"content":{"rendered":"<p>I&#8217;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\u00a0has been working for the last few weeks, ever since <a href=\"https:\/\/msdn.microsoft.com\/commandline\/wsl\/release_notes#build-14986\">#14986<\/a> in fact, but it appears that we&#8217;d not explicitly communicated the fact, so &#8230; here we are!\u00a0\ud83d\ude42<\/p>\n<h2 style=\"text-align: center\">\n  <span style=\"color: #ff6600\"><strong>Haskell now runs in Bash on Windows!*<\/strong><\/span>\n<\/h2>\n<p>** You&#8217;ll need to be running Windows 10 Insider build #14986 or later.*<\/p>\n<h3>Background<\/h3>\n<p><a href=\"https:\/\/en.m.wikipedia.org\/wiki\/Haskell_(programming_language)\">Haskell<\/a> is a popular and powerful functional programming language which wasn&#8217;t able to run on Bash\/WSL in Anniversary Update or earlier Insider builds, because <a href=\"https:\/\/github.com\/Microsoft\/BashOnWindows\/issues\/307\">WSL\u00a0had not yet implemented the <code>timer_create()<\/code> syscall<\/a>. Now that WSL builds >= #14986 do support timer_create() we can run Haskell and many other tools (e.g. Elm, Cabal, Pandoc, Agda,\u00a0etc.) \ud83d\ude42<\/p>\n<p>Note: You can, as with most modern dev tools, also run\u00a0Haskell 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!<\/p>\n<h3>Hello World in Haskell<\/h3>\n<p>Let&#8217;s create a Haskell Hello World sample:<\/p>\n<p>First, install the Glasgow Haskell Compiler:<\/p>\n<p>$ sudo apt install ghc<\/p>\n<p>While we could run the Haskell interactive REPL, the GHC compiler can, of course, also compile Linux executables:<\/p>\n<p>Open your favorite Linux editor (mine is Vim) creating a new <code>hello.hs<\/code> file<\/p>\n<pre>$ vim hello.hs<\/pre>\n<p>Now enter the following Haskell code:<\/p>\n<pre>main = putStrLn \"Hello World!\"<\/pre>\n<p>This\u00a0declares a <code>main<\/code> function\u00a0whose implementation calls putStrLn that writes &#8220;Hello World&#8221; to stdout.<\/p>\n<p>After exiting your editor (:wq[Enter] in Vim ;)), compile this file by typing the\u00a0following:<\/p>\n<pre>$ ghc hello.hs -o hello\n[1 of 1] Compiling Main\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ( hello.hs, hello.o )\nLinking hello ...<\/pre>\n<p>This will\u00a0generate a Linux ELF64 binary file called <code>hello<\/code>, along with\u00a0<code>hello.hi<\/code> and <code>hello.o<\/code>, which are just intermediate compilation files. You can check the hello binary using the\u00a0<code>file<\/code> tool:<\/p>\n<pre>$ file hello\nhello: <strong>ELF 64-bit LSB executable, x86-64<\/strong>, version 1 (SYSV), dynamically linked, interpreter \/lib64\/ld-linux-x86-64.so.2, for GNU\/Linux 2.6.32, BuildID[sha1]=0296a5fedb69302e0310bbcb7a8bea8f860a52c5, not stripped<\/pre>\n<p>You can\u00a0now run the binary (note: the .\/ prefix is required when\u00a0executing a local binary):<\/p>\n<pre>$\u00a0.\/hello \u00a0Hello World!<\/pre>\n<p>Congratulations, you&#8217;re now <a href=\"https:\/\/wiki.haskell.org\/Haskell\">on your way to being a Haskell\u00a0guru<\/a> \ud83d\ude42<\/p>\n<p>\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;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\u00a0has been working for the last few weeks, ever since #14986 in fact, but it appears that we&#8217;d not explicitly communicated the fact, so &#8230; [&hellip;]<\/p>\n","protected":false},"author":910,"featured_media":4543,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[22,42,56],"class_list":["post-835","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash-on-ubuntu-on-windows","tag-bash","tag-linux","tag-syscalls"],"acf":[],"blog_post_summary":"<p>I&#8217;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\u00a0has been working for the last few weeks, ever since #14986 in fact, but it appears that we&#8217;d not explicitly communicated the fact, so &#8230; [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/posts\/835","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/users\/910"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/comments?post=835"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/posts\/835\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/media\/4543"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/media?parent=835"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/categories?post=835"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/tags?post=835"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}