Skip to content
Stian Håklev edited this page Mar 4, 2015 · 17 revisions

Exemplary IHaskell Notebooks

Using IHaskell

IPython

IHaskell is based upon the IPython architecture and frontend, so learning about that will help. You can write your own extensions using the IPython javascript API, for instance. Use h to learn more about the modal interface IHaskell/IPython provides.

IHaskell adds a few features on top of the IPython frontends, such as automatic character concealing (typing -> yields an arrow) and input cell folding (via the left and right arrow keys, or the buttons). If input cell folding isn't showing up, you can explicitly enable it via the "Cell Toolbar" (select 'Hiding').

Directories

IHaskell looks for notebook files (with the extension .ipynb) in ~/.ihaskell/notebooks by default. You can change that via ihaskell notebook --serve=directory or equivalent ihaskell notebook -s directory.

The working directory of the scripts defaults to wherever you're running the ipython instance from. You can change that via :!cd my_new_dir.

Shelling out

You can run simple shell commands with :!cmd, for example :!cd /. The shell is persistent (ie. if you cd somewhere in one cell, and ls in the next, it will be in the directory you went to).

If you want to include values from Haskell, you can use a quasiquoter (via :set -XQuasiQuotes). For instance, using System.ShQQ, you could write something like

let x = "foo bar" in [sh| cat $x |]

IHaskell Directives

Many of the directives are shared with GHCi for the sake of convenience, though they do not necessarily behave in the exact same ways.

:set, :ext, :opt

Use :set to set flags (like GHCi set) and :ext to enable or disable extensions. (See below for more detail). :opt can be used to set IHaskell-specific options, such as :set no-pager.

:type

:type or :t is similar to that in GHCi, and shows the type of an expression.

:kind

:kind or :k is similar to that in GHCi, and shows the kind of a type. However, :kind! is not available at the moment; file an issue if that is important to you.

In-notebook settings:

Enable/disable GHC extensions

Example: :extension DataKinds NoExtendedDefaultRules Alternative: :set -XDataKinds -XNoExtendedDefaultRules

Set Dynamic flags

You can use :set in a similar manner to GHCi, e.g., set -XDataKinds.

:opt [no-]show-types

Default off. Shows types of return values (similar to :set +t in GHCi).

:opt [no-]lint

Default on. Uses HLint to show suggestions for improvements.

:opt [no-]svg

Default on. Images from supporting libraries (such as Chart and Diagrams) are shown as SVG in the notebook. SVG images cannot at the moment be resized by the user clicking an dragging on a handle. When no-svg is set, displays use PNG instead, which can be resized in the notebook.

:opt [no-]show-errors

Default off. By default, errors due to evaluating expressions that don't have a Show instance are displayed as an unshowable button: When clicked, it displays the whole Show error message.

To disable this and just show the error message by default (no button), use :opt show-errors.

:opt [no-]pager

Default on. By default, things such as :info and :doc go to the IPython pager. However, if you'd like them to persist, you can instead direct them into the output area of the cell via :opt no-pager.