IHaskell on Windows!

Arvind Devarajan
Techscape
Published in
4 min readNov 18, 2018

--

IHaskell on WSL (OpenSUSE) on Windows 10

If you ever have wanted IHaskell, and also wanted that on Windows, the first thing that can disappoint you are these wordings in the installation page:

IHaskell on Windows from https://github.com/gibiansky/IHaskell

Of course, a VirtualBox is a good choice. On professional version of Windows, installation of a complete Linux distribution on Hyper-V is also a choice, if you are successful in actually doing so.

But nothing comes close to getting IHaskell on the Windows Subsystem for Linux (WSL). Which is what this article is about. The obvious advantage of using IHaskell on WSL is the fact that it looks very natural on a Windows system, not to forget that you have no need to depend on third-party solutions like VirtualBox to get your Linux on. And, of course, for low-memory systems (even with about 4GB RAM), IHaskell on WSL could be your only best choice.

So, what does it take to get IHaskell on Windows?

We first should make some priliminary adjustments to the WSL environment to push our home-directories to a non-system drive on Windows. As of this writing WSL installs only on the system-drive C:, and since hence all Haskell-installations get into our root-filesystem / home directory in Linux, all these fall into the system-drive C:. Since C: is a precious drive that you would not want to mess with, I find it safer to move our WSL home to a non-system drive that is mounted in /mnt. For doing so, and getting the Haskell and Haskell-Stack on your WSL, we have a separate article here — go there and follow the instructions to get Haskell on your system.

Installation of Jupyter (via Anaconda)

Having done that, we need to install Jupyter on WSL as IHaskell needs it. I simply went the Anaconda way, and downloaded the Anaconda distribution which comes with Jupyter. Before actually installing Jupyter in my system, add these in your ~/.profile to make sure Jupyter installs its files in the right directories (i.e., not in C:). Substitute the directories with your own locations.

export JUPYTER_HOME=/mnt/e/opensuse/tools/jupyter
export JUPYTER_CONFIG_DIR=${JUPYTER_HOME}/config
export JUPYTER_DATA_DIR=${JUPYTER_HOME}/data
export JUPYTER_RUNTIME_DIR=${JUPYTER_HOME}/runtime

Finally, just go ahead and install Anaconda. Additionally, I also keep my Jupyter notebooks in a specific directory: ${JUPYTER_HOME}/notebook. If you also want to do this, you need to first create a jupyter configuration, and then set the location of the notebooks in the generated configuration file.

# Generate Jupyter configuration for notebooks
jupyter notebook --generate-config
# Inside the generated config file jupyter_notebook_config.py
# uncomment this line and add the notebook location
c.NotebookApp.notebook_dir = '/mnt/e/opensuse/tools/jupyter/notebooks'

Installation of IHaskell

Having done that, we move on to getting IHaskell. Most of the instructions are clear already in IHaskell’s page: https://github.com/gibiansky/IHaskell. I just have made small changes to this since I use OpenSuSE on WSL.

First, install the necessary packages on OpenSUSE (at the time of writing this, I had OpenSUSE Leap 15):

sudo zypper install -n python3-pip git ncurses-devel zeromq-devel cairo-devel pango-devel file-devel blas-devel lapack-devel

Finally, here are the instructions for installing IHaskell on OpenSuSE on WSL

cd /mnt/e/opensuse/tools
git clone https://github.com/gibiansky/IHaskell
cd IHaskell
sudo pip3 install -r requirements.txt
stack install gtk2hs-buildtools
stack install --fast
ihaskell install --stack

The stack install --fast seemed to fail during the build of cryptonite-0.25:

--  While building package cryptonite-0.25 using:
/mnt/e/opensuse/tools/haskellstack/setup-exe-cache/x86_64-linux-tinfo6/Cabal-simple_mPHDZzAJ_2.2.0.1_ghc-8.4.4 --builddir=.stack-work/dist/x86_64-linux-tinfo6/Cabal-2.2.0.1 build --ghc-options " -ddump-hi -ddump-to-file -fdiagnostics-color=always"
Process exited with code: ExitFailure 1
Logs have been written to: /mnt/e/opensuse/tools/IHaskell/.stack-work/logs/cryptonite-0.25.log
Configuring cryptonite-0.25...
Preprocessing library for cryptonite-0.25..
Building library for cryptonite-0.25..
[ 1 of 123] Compiling Crypto.Cipher.DES.Primitive ( Crypto/Cipher/DES/Primitive.hs, .stack-work/dist/x86_64-linux-tinfo6/Cabal-2.2.0.1/build/Crypto/Cipher/DES/Primitive.o )
[ 2 of 123] Compiling Crypto.Data.Padding ( Crypto/Data/Padding.hs, .stack-work/dist/x86_64-linux-tinfo6/Cabal-2.2.0.1/build/Crypto/Data/Padding.o )
[ 3 of 123] Compiling Crypto.Internal.Compat ( Crypto/Internal/Compat.hs, .stack-work/dist/x86_64-linux-tinfo6/Cabal-2.2.0.1/build/Crypto/Internal/Compat.o )
.....
.....
[120 of 123] Compiling Crypto.ECC ( Crypto/ECC.hs, .stack-work/dist/x86_64-linux-tinfo6/Cabal-2.2.0.1/build/Crypto/ECC.o )
[121 of 123] Compiling Crypto.PubKey.ECIES ( Crypto/PubKey/ECIES.hs, .stack-work/dist/x86_64-linux-tinfo6/Cabal-2.2.0.1/build/Crypto/PubKey/ECIES.o )
[122 of 123] Compiling Crypto.Data.AFIS ( Crypto/Data/AFIS.hs, .stack-work/dist/x86_64-linux-tinfo6/Cabal-2.2.0.1/build/Crypto/Data/AFIS.o )
[123 of 123] Compiling Crypto.Tutorial ( Crypto/Tutorial.hs, .stack-work/dist/x86_64-linux-tinfo6/Cabal-2.2.0.1/build/Crypto/Tutorial.o )
/mnt/e/opensuse/tools/haskellstack/snapshots/x86_64-linux-tinfo6/lts-12.18/8.4.4/pkgdb/package.cache: openBinaryFile: invalid argument (Invalid argument)

However, on simply running stack install --fast solved this. Since it just worked, I simply did not investigate on why this failed in the first place — so any hints on this will be appreciated.

Starting Jupyter and using IHaskell

Simply start juputer like this:

jupyter notebook --no-browser

On firing up a browser and navigating to http://localhost:8888, you’ll be pleasantly surprised seeing IHaskell on your Windows machine with all its glory!

Making this all look “natural” on Windows

I like to start Jupyter via the start-menu. All I did was to create batch-file with these contents:

@echo off
start /min bash --login -c 'jupyter notebook --no-browser'
timeout /t 5 /nobreak > NUL
start http://localhost:8888

And created a shortcut to this batch-file in the start-menu. Lo and behold! Jupyter now starts “naturally” on Windows! The command-prompt it opens for starting Jupyter is, although looking out-of-place, is important because that’s the way to stop jupyter when your work is done.

Enjoy IHaskell on Windows! And make sure to clap if you find this useful!

--

--