Installing Reactive Banana on Ubuntu 16.04

3 minute read

In the days leading up to the Christmas holidays last year I was searching for a little project that I could work on. After some consideration I settled on trying to build a Tetris clone in Haskell. Funky, right?

Beautiful, right?

To make a long story short I failed to even get started. I would have liked to use reactive banana, which I chose because it has some games as example code. Always useful, such things. Anyway, I simply could not get the examples running. These days I got a bit bored, so I figured I should probably try again. This time I succeeded - I installed reactive banana and running the basic examples. Since the whole process was pretty contrived, I figured “Why not write about it? Might help someone, somewhere, sometime.”.

Disclaimer: I am an utter N00b when it comes to Haskell. So, if you have years of experience with the whole ecosystem surrounding Haskell, I apologize in advance.

Installation

This write-up assumes you have things like ghc and cabal already installed. If you don’t you might want to just get the Haskell Platform as it contains everything mentioned above and a bit more. For the record, I myself am using ghc 8.0.1 and cabal 1.24.0.0.

After we got that out of the way the first thing you want to do is head over to Github and download or clone the reactive banana source code. You might also want to have a look at the readme, because we will more or less follow the steps detailed there. Let’s try to install reactive banana from source.

cd reactive-banana && cabal install && cd ..

If you got lucky that will work. You may verify that the reactive-banana package was installed on your system by running

cabal list --installed reactive

As the readme explains, that in itself is not enough to run the interactive GUI examples that come with the source code. An overview over the examples can be found here. The corresponding source code lies in the reactive-banana-wx directory.

The next step is to install wxHaskell.

cabal install wx

If you got unlucky (like me), you will have to install some dependencies, namely wxWidgets. Head over to their homepage and download the 3.0.2 release.

Do not download the latest release, because right now wxWidgets 3.1.x is not compatible with wxHaskell.

You are required to build wxWidgets yourself from source. You can do so by following the installation instructions for Linux. The relevant part is running the following commands in the wxWidgets folder:

./configure --disable-shared –enable-unicode
make -j
make install

That usually takes some time, so go grab a coffee or another beverage of your choice. If it worked - great. If it didn’t - I’m sorry, you will have to figure out why compilation failed yourself. Maybe you are missing some development libraries?

sudo apt-get install libgtk-3-dev build-essential checkinstall

Now retry installing wxHaskell. If installing with cabal still failed (like it did for me) you will have to install wxHaskell from source too. So head over to their Github repo and download the source. Follow the instructions in the install.txt for wxHaskell 0.90.

cabal update
cd wxdirect
cabal install
cd ../wxc
cabal install
cabal install
cd ../wx
cabal install

I sincerely hope that worked for you. To be honest, I am not sure why installing from source worked as opposed to installing from hackage. Once that is done with, you have (theoretically) installed all “big” dependencies for building the examples. Now in the reactive-banana-wx directory run:

cabal configure -fbuildExamples && cabal build

Possibly that will fail because some dependencies are not satisfied. I my case, I had never version of the dependencies installed. You might be able to resolve those errors by adjusting the reactive-banana-wx.cabal file. Find the code blocks that specify the dependencies for each example. They should look something like this:

if flag(buildExamples)
        build-depends:
            process >= 1.0 && <= 1.5,
            random >= 1.0 && <= 1.1,
            executable-path == 0.0.*,
            filepath >= 1.1 && <= 1.4.1.2,
            reactive-banana, wx, wxcore, base
        cpp-options: -DbuildExamples

Note that the example above has already been adjusted to reflect the dependencies installed on my system (namely filepath and process). In case some dependencies are flat out missing, you can install them using cabal, for example:

cabal install filepath-1.4.1.2

Once all dependencies have been adjusted you should be able to build the examples. They are contained in the dist/build directory.

cd ./dist/build
./Asteroids

I had - well, let’s call it fun - figuring everything I described here out. I hope that this post was helpful to you. Enjoy your game of Asteroids and happy coding!

Updated: