IHaskell is a kernel for the Jupyter project, which allows you to use Haskell inside Jupyter frontends (including the console and notebook). It currently supports GHC 8.4 through 9.10.
You can now try IHaskell directly in your browser at mybinder.org.
For a tour of some IHaskell features, check out the demo Notebook. More example notebooks are available on the wiki. The wiki also has more extensive documentation of IHaskell features.
Install Haskell with via ghcup.
For MacOS you need to have Homebrew installed. You also need the Xcode command line tools. You can install them by running xcode-select --install in the terminal and following the prompts.
System pre-requisites:
- MacOS:
brew install python3 zeromq libmagic cairo pkg-config pango - Linux:
sudo apt-get install -y python3-pip git libtinfo-dev libzmq3-dev libcairo2-dev libpango1.0-dev libmagic-dev libblas-dev liblapack-dev
Python pre-requisites:
- Jupyter:
pip3 install jupyter
cabal install ihaskellihaskell install --ghclib=$(ghc --print-libdir) --prefix=$HOME/.local/jupyter kernelspec install $HOME/.local/share/jupyter/kernels/haskell/
To confirm success run jupyter kernelspec list and you should see a Haskell kernel installed. Start jupyter with jupyter notebook
git clone https://github.com/IHaskell/IHaskellcd IHaskellcabal build && cabal install exe:ihaskell --overwrite-policy=always --force-reinstalls --installdir=/home/$USER/.cabal/bin/ --install-method=copyihaskell install --ghclib=$(ghc --print-libdir) --prefix=$HOME/.local/jupyter kernelspec install $HOME/.local/share/jupyter/kernels/haskell/
Install stack via ghcup tui.
These instructions assume you don't already have Stack or a Jupyter installation, please skip the relevant steps if this is not the case.
git clone https://github.com/IHaskell/IHaskell
cd IHaskell
pip3 install -r requirements.txt
stack install --fast
ihaskell install --stackRun Jupyter.
stack exec jupyter -- notebookIf you have Homebrew installed to a location that
stackdoes not expect (e.g./opt/homebrew), you'll need to specify--extra-include-dirs ${HOMEBREW_PREFIX}/include --extra-lib-dirs ${HOMEBREW_PREFIX}/libto thestackcommand.
Tested on macOS Sierra (10.12.6)
IHaskell does not support Windows, however it can be used on Windows 10 via Windows Subsystem for Linux (WSL). If WSL is not installed, follow the Installation Guide for Windows 10. The following assumes that Ubuntu is picked as the Linux distribution.
In the Ubuntu app, follow the steps above for Linux.
Jupyter Notebook is now ready to use. In the Ubuntu app, launch a Notebook Server, without opening the notebook in a browser:
jupyter notebook --no-browserReturning to Windows 10, open a browser and copy and paste the URL output in the step above (the token will differ).
Or copy and paste one of these URLs:
http://localhost:8888/?token=9ca8a725ddb1fdded176d9e0e675ba557ebb5fbef6c65fdfTested on Windows 10 (build 18362.175) with Ubuntu 18.04 on WSL
Alternatively, install Virtualbox, install Ubuntu or another Linux distribution, and proceed with the install instructions.
To quickly run a Jupyter notebook with the IHaskell kernel, try the Dockerfile
in the top directory.
docker build -t ihaskell:latest .
docker run --rm -p 8888:8888 ihaskell:latestOr use the continuously updated Docker image on Docker Hub.
docker run --rm -p 8888:8888 gibiansky/ihaskellIn order to mount your own local files into the Docker container use following command:
docker run --rm -p 8888:8888 -v "$PWD":/home/jovyan/src gibiansky/ihaskellBe aware that the directory you're mounting must contain
a stack.yaml file.
A simple version would be:
resolver: lts-16.23
packages: []It's recommended to use the same LTS version as the IHaskell image is using itself (as can be seen in its stack.yaml). This guarantees that stack doesn't have to first perform a lengthy installation of GHC before running your notebook.
You can also use the following script to run IHaskell in Docker: https://gist.github.com/brandonchinn178/928d6137bfd17961b9584a8f96c18827
If you have the nix package manager installed (and have
flakes enabled), you can create an IHaskell
notebook environment with one command. For example:
$ nix build
<result path>
$ <result path>/bin/jupyter notebookIt might take a while the first time, but subsequent builds will be much faster. You can use the https://ihaskell.cachix.org cache for prebuilt artifacts.
The IHaskell display modules are not loaded by default and have to be specified separately:
$ nix build .#ihaskell-env-display-ghc98For more examples of using IHaskell with Nix, see https://github.com/vaibhavsagar/notebooks.
IHaskell is regularly updated to work with the latest version of GHC. To read how this is done, and how the development environment is set up, please see this blog post.
There is also a Nix flake that provides a developer environment. For details on Nix flakes, please see the documentation at https://wiki.nixos.org/wiki/Flakes.
After this, IHaskell can be compiled as follows:
nix develop # This opens a new shell with all dependencies installed
cabal update # Make sure Cabal's package index is up-to-date
cabal build # Builds IHaskellNote that this shell also provides haskell-language-server, which can be used in your editor if it supports it. Opening your editor from within the nix develop shell should allow it to see haskell-language-server.
Stack manages separate environments for every package. By default your notebooks
will only have access to a few packages that happen to be required for
IHaskell. To make packages available add them to the stack.yaml in the IHaskell
directory and run stack install --fast.
Packages should be added to the packages: section and can take the following
form
(reproduced here from the stack documentation). If
you've already installed a package by stack install you can simply list its
name even if it's local.
- package-name
- location: .
- location: dir1/dir2
- location: https://example.com/foo/bar/baz-0.0.2.tar.gz
- location: http://github.com/yesodweb/wai/archive/2f8a8e1b771829f4a8a77c0111352ce45a14c30f.zip
- location:
git: [email protected]:commercialhaskell/stack.git
commit: 6a86ee32e5b869a877151f74064572225e1a0398
- location:
hg: https://example.com/hg/repo
commit: da39a3ee5e6b4b0d3255bfef95601890afd80709
The default instructions globally install IHaskell with support for only one
version of GHC. If you've e.g. installed an lts-10 IHaskell and are using it
with an lts-9 project the mismatch between GHC 8.2 and GHC 8.0 will cause
this error. Stack also has the notion of a 'global project' located at
~/.stack/global-project/ and the stack.yaml for that project should be on
the same LTS as the version of IHaskell installed to avoid this issue.

