Skip to content
A Haskell kernel for IPython.
Jupyter Notebook Haskell Nix JavaScript Dockerfile TypeScript Shell
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
demo
docker Dockerfile refactor Jun 3, 2019
ghc-parser Use parseDynamicFilePragma Jul 10, 2019
html html/kernel.js: don't set autoCloseBrackets Aug 2, 2019
ihaskell-display rm ihaskell-display/ihaskell-*/stack.yaml Jun 3, 2019
ihaskell_labextension ihaskell_labextension for JupyterLab 1.0.0 Jul 11, 2019
images Adding documentation and removing Docker (for now) Mar 26, 2015
ipython-kernel ipython-kernel: fix warnings Aug 3, 2019
main Move busy message as well May 21, 2019
notebooks notebooks/IHaskell.ipynb: get docs for more constrained type May 31, 2019
src IHaskell.Test.Parser: fix test failure on GHC 8.8 Aug 29, 2019
test
.dockerignore Added and tested Dockerfile and instructions on how to use it Feb 1, 2016
.ghci Remove default flags; they break ghci Mar 13, 2017
.gitignore Add nix derivations Jul 24, 2017
.travis.yml .travis.yml: pin Stack Jun 22, 2019
Dockerfile Dockerfile: remove `stack setup` Jun 29, 2019
LICENSE
README.md README.md: link to vaibhavsagar/notebooks Aug 7, 2019
Setup.hs Fix formatting with newer hindent Aug 25, 2015
cabal.project cabal.project: init Apr 4, 2018
ihaskell.cabal ihaskell.cabal: bump upper bound on ghc-boot dependency Aug 4, 2019
release-8.6.nix release{,-8.6}.nix: update for 19.03 Apr 11, 2019
release-8.8.nix release-8.8.nix: bump nixpkgs-src Aug 29, 2019
release.nix release.nix: be explicit about using coreutils for tr Aug 12, 2019
requirements.txt requirements.txt: use jupyter-core 4.5.0 Jun 28, 2019
stack-8.0.yaml ihaskell-widgets: Turn on -Wall and fix all warnings Sep 3, 2018
stack-8.2.yaml stack.yaml: use GHC 8.4.3 Oct 23, 2018
stack-8.4.yaml Switch to lts-13 as the default resolver Jan 5, 2019
stack.yaml Bump resolver to lts-13.26 Jun 22, 2019

README.md

jupyter IHaskell Build Status Binder

IHaskell

You can now try IHaskell directly in your browser at CoCalc or mybinder.org.

Alternatively, watch a talk and demo showing off IHaskell features.

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, 8.2, 8.4, and 8.6. For GHC 7.10 support please use the GHC7 tag.

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.

IPython Console IPython Notebook

Interactive In-Browser Notebook

Installation

Linux

Some prerequisites; adapt to your distribution.

sudo apt-get install -y python3-pip git libtinfo-dev libzmq3-dev libcairo2-dev libpango1.0-dev libmagic-dev libblas-dev liblapack-dev

Install stack, clone this repository, install Python requirements, install ihaskell, and install the Jupyter kernelspec with ihaskell.

curl -sSL https://get.haskellstack.org/ | sh
git clone https://github.com/gibiansky/IHaskell
cd IHaskell
pip3 install -r requirements.txt
# stack install gtk2hs-buildtools # Disabled for now because gtk2hs-buildtools doesn't work with lts-13 yet
stack install --fast
ihaskell install --stack

If you want to use jupyterlab (right now only version ~0.33), you need to install the jupyterlab ihaskell extension to get syntax highlighting with:

jupyter labextension install ihaskell_jupyterlab

Run Jupyter.

stack exec jupyter -- notebook

Mac

You need to have Homebrew installed. If you do not have it yet run /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" in your terminal.

You also need the Xcode command line tools. You can install them by running xcode-select --install in the terminal and following the prompts.

brew install python3 zeromq libmagic cairo pkg-config haskell-stack pango
git clone https://github.com/gibiansky/IHaskell
cd IHaskell
pip3 install -r requirements.txt
# stack install gtk2hs-buildtools # Disabled for now because gtk2hs-buildtools doesn't work with lts-13 yet
stack install --fast
ihaskell install --stack

If you have Homebrew installed to a custom location, you'd need to specify --extra-include-dirs ${HOMEBREW_PREFIX}/include --extra-lib-dir ${HOMEBREW_PREFIX}/lib to the stack command.

Run Jupyter.

stack exec jupyter -- notebook

Tested on macOS Sierra (10.12.6)

Windows

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-browser

Returning 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=9ca8a725ddb1fdded176d9e0e675ba557ebb5fbef6c65fdf

Tested 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.

Docker

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 -it -p8888:8888 ihaskell:latest

Stack and Docker

IHaskell, being a Jupyter kernel, depends at runtime on a tall pile of software provided by, traditionally, apt, pip, and npm. To develop IHaskell, we want to be able to isolate and control all of the dependencies. We can use Stack's Docker integration to install all of those runtime dependencies into an isolated environment.

  • The system library dependencies installed with apt will be isolated in the ihaskell-dev Docker image.
  • Dependencies installed by pip and npm will be isolated in the IHaskell/.stack-work subdirectory.
  • All Stack build products and installed binaries will be isolated in the IHaskell/.stack-work subdirectory.

The following stack --docker commands require a Docker image named ihaskell-dev, so build that image from the docker/Dockerfile with this command:

docker build -t ihaskell-dev docker

Install the ghc version specified by the Stack resolver.

stack --docker setup

Install Jupyter and all of its requirements.

stack --docker exec pip3 -- install jupyter

Build IHaskell and all of its packages.

stack --docker install

Direct IHaskell to register itself as a Jupyter kernel.

stack --docker exec ihaskell -- install --stack

Optionally, install JupyterLab and the IHaskell JupyterLab extension for syntax highlighting. See the ihaskell_labextension/README.md.

stack --docker exec pip3 -- install jupyterlab
stack --docker exec bash -- -c 'cd ihaskell_labextension;npm install;npm run build;jupyter labextension link .'

Run the Jupyter notebook, with security disabled for testing.

stack --docker exec jupyter -- notebook --NotebookApp.token='' notebooks

Run JupyterLab (if you installed it), with security disabled for testing.

stack --docker exec jupyter -- lab --NotebookApp.token='' notebooks

Everything in Stackage can be installed by stack --docker install.

To install a local package, add it to the stack.yaml file (See: "Where are my packages?" below). Install the package with stack, then restart jupyter.

# after adding details about mypackage to stack.yaml
stack --docker install mypackage

To cleanly delete the entire Stack Docker development environment:

docker image rm ihaskell-dev
stack clean --full

Nix

If you have the nix package manager installed, you can create an IHaskell notebook environment with one command. For example:

$ nix-build -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-19.03.tar.gz --argstr compiler ghc864 --arg packages "haskellPackages: [ haskellPackages.lens ]"
<result path>
$ <result path>/bin/ihaskell-notebook

It might take a while the first time, but subsequent builds will be much faster.

The IHaskell display modules are not loaded by default and have to be specified as additional packages:

$ NIXPKGS_ALLOW_BROKEN=1 nix-build -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-19.03.tar.gz --argstr compiler ghc844 --arg packages "haskellPackages: [ haskellPackages.ihaskell-blaze haskellPackages.ihaskell-charts ]"

We use GHC 8.4 here because not all dependencies have been updated to support GHC 8.6 yet.

For more examples of using IHaskell with Nix, see https://github.com/vaibhavsagar/notebooks.

Troubleshooting

Where are my packages? (IHaskell + Stack)

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 solver && stack install.

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: git@github.com:commercialhaskell/stack.git
    commit: 6a86ee32e5b869a877151f74064572225e1a0398
- location:
    hg: https://example.com/hg/repo
    commit: da39a3ee5e6b4b0d3255bfef95601890afd80709

The kernel keeps dying (IHaskell + Stack)

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.

openFile: does not exist (Stack + Docker)

If you try to run a notebook with stack --docker and see an IHaskell kernel error that looks like this:

ihaskell: /opt/ghc/8.6.5/lib/ghc-8.6.5/settings: openFile: does not exist

Then delete your ~/.stack directory and start over.

You can’t perform that action at this time.