Ihaskell + dataframe integration

After struggling a fair amount with ihaskell I managed to get a very brittle setup going and an accompanying example.

Learnings:

  • It’s great that ihaskell is still actively maintained and that plotting is extremely easy. Plus there are a lot of options for plotting.
  • Making things work is still very painful. I’m trying to roll everything up into a docker container and put it behind a web app/mybinder to avoid having users deal with the complexity.

Has anyone had any success doing something similar?

8 Likes

I have never managed to get custom packages working with the default Dockerfile included with IHaskell. However, I have had success using ihaskell-notebook to build a Docker container, with a fork containing my own version updates and packages. I have a couple of public notebooks one could try out on mybinder which take advantage of this.

1 Like

Thank you so much. This was easier to follow and read than the docker file in the IHaskell directory.

Managed to get it on azure.

Nix worked reasonably well for me for setting up ihaskell + whatever libraries are used. But this requires nix and all accompanying problems. It’s possible to build docker images with nix as well though

Also what did you use for plotting? I gave up on plotting in haskell and just use matplotlib.

Haven’t worked with nix extensively. Might be worth learning in that case. Although the ihaskell-notebook suggestion seems to have worked for me.

Still actively working on plotting. Gnuplot seems to be the least fussy but:

  • Fails silently if there is an error or the data is too large
  • Doesn’t automatically do binning for histograms so you have to write your own binning logic.

I haven’t worked with the Haskell matplotlib bindings, are they easy to setup?

I just call python functions directly with inline-python. It mostly just works (almost, with nix one needs to set PYTHONHOME so python interpreter will look up libraries at correct path). I’m playing with tighter integration but it’s all very experimental

P.S. There’s matplotlib library which is huge hack and not particularly pleasant to use.

Seems like charts is pretty decent at least for ihaskell.

2 Likes

I think charts’ API is quite broken. It made poor choice of determining axis type linear/log/categorical from type of element being plotted. And this means it’s difficult to switch between linear-log scales: you need to fmap every point being plotted. It’s terribly verbose on top of it.

But plots are quite nice looking

1 Like

Interesting. Haven’t used it enough to see. I was beguiled by nice look charts. Of the options that come natively in ihaskell it seems they all have some non trivial drawbacks. The matplotlib bindings seem to do something that looks to me like calling Python.

https://hackage.haskell.org/package/matplotlib-0.7.7/docs/src/Graphics.Matplotlib.html#dataPlot

How does this differ from what the inline-python library does? And is online python usable with ihaskell?

And code that does drawing is fine. In principle one could replace API for creating plots with better API (caveat it should be better). But that would be huge project.

Indeed! It generated python code and pipes it into python interpreter. inline-python allows one to have python interpreter in same address space and call it at will, interleave haskell and python. As an example:

{-# LANGUAGE QuasiQuotes #-}
module MPL where

import Python.Inline
import Python.Inline.QQ

main :: IO ()
main = do
  initializePython
  runPyInMain [pymain| import matplotlib.pyplot as plt |]
  let xs = [1 .. 100::Int]
      ys = [x*x | x <- xs]
  runPyInMain [py_|
    plt.plot(xs_hs, ys_hs)
    plt.show()
    |]

Interfacing with ihaskell should be possible. But probably won’t be easy