Demo of IHaskell Notebook

January 20, 2016

Andrew Gibiansky shows some examples of using IHaskell Notebook, a capable graphical alternative to GHCI. He demonstrates how it can shorten development feedback loops in applications from graphs to parsers, and how the results, a.k.a. notebooks, are easy to share with other people.


  • IHaskell is based on Jupyter and provides an interactive environment for Haskell DSLs
  • There used to be a project called iPython
    • It started out unambitiously, as a a fancy .pythonrc to configure their repl
    • As it grew it became fancier and the creators added a new front end and GUI
    • Two or three years ago they abstracted the interactive framework beyond Python into Jupyter
    • Works for any language
  • The architecture of Jupyter’s messaging protocol
  • How to use a notebook
    • The notebook is composed of cells. Some are markdown cells, formatted with Github flavor
    • Some are code cells with anything you could put into GHCI but also multiline expressions
    • Possible to run the evaluation server remotely on strong hardware
  • The main advantage over GHCI is that you can do fancy visualizations
    • If this were just a way of doing multi-line computations then it would be pretty boring
    • Example of using the diagrams package to build Sierpinski Triangles
    • Supports LaTeX in the markdown too!
    • Any library that wants to render graphics creates instances of the IHaskellDisplay typeclass
  • Exporting and Sharing
    • Easy to export to HTML which is fully self-contained
    • You could email the HTML or use it in a blog
    • It’s an alternative to literate Haskell with embedded output
  • Interactivity
    • So far we’ve edited and re-run existing code cells, but the tool capable of more
    • We can add display widgets (like a slider) and bind them to code properties
    • This is the result of a Google Summer of Code project from 2015
    • (Digression on do and let in the repl)
    • Example of binding the slider to rotation angle of the Spierpinski Triangle
  • Another example of a display widget, and one that Andrew has gotten more use out of, is parsing
    • Let’s make an interactive widget for testing parsers
    • We’ll do a phone number parser, but a more hefty parser is where the technique would really shine
    • When investigating what you can do with a display field, call the properties function on it
    • First attempt is to take a string input and update an output area
    • Final result parses input live and shows parse errors or successful result
  • In future Andrew would like to connect this with GHCJS
  • Notes of other miscellaneous features
    • Environment-aware autocompletion
    • Hoogle and hlint integration
    • Visualization support for a dozen Haskell libraries (Chart, diagrams, hatex, juicypixels, etc)
    • Support for displaying custom datatypes of your own
    • Library for using the same interfaces with your own languages (ICryptol, someday IIdris?)
    • Export as presentations
  • Doesn’t know about the .cabal file, but knows about the stack.yml