Running Haskell on Linux…on Android

Have an Android phone with a bunch of unused free disk space? Want to code Haskell on it? Don’t like the idea of rooting your phone and risking bricking it just to install a compiler? Are you filled with a bizarre desire to develop code on a tiny device with a tiny screen? Do you want to experience the epic smugness that can only result from someone looking over your shoulder and saying “are…are you doing that on your phone?!” If so, then these instructions are for you!

If you have a beefy enough phone, then you can install a Linux virtual machine without rooting and put regular Haskell Platform on top of it – all without rooting the phone. The setup described below is 100% free. Making things even better, at least at the time I’m writing this (Jan 2019), there are no advertisements in any of the apps and they are all available on Google Play and compatible with Android 8. You will need need quite a few GB of free space – probably around 10GB to be safe, more like 15-20 being better to leave some wiggle room after you install everything. Here’s what it looks like in action:


Successfully running Haskell on Linux on Android.


Before We Begin…

Lest my peppy intro be misleading, there are three rather big caveats to be aware of before sinking time into trying this kind of setup:

  1. You will get Haskell Platform 8.0.1, which is may be too old for some purposes (the most recent version as I’m writing this is 8.6.3).
  2. There is no sound – at least not through the same app that you use to run Haskell via Linux. You will need to write MIDI files or something and then play it through another application. However, if using something like Euterpea, you won’t be able to use the “play” command (you’ll have to use “writeMidi” instead).
  3. Setup takes time. Successfully proceeding through the entire setup requires patience. It is slow and also prone to a combination of server timeouts and VM stalls if something goes wrong during that slowness (you’ll see a “connection lost” message in either ssh or vnc). So get ready to run
    sudo dpkg --configure -a

    whenever something doesn’t work on the first try. The bright side is that these things only were an issue during setup, for me at least.

Installing Haskell on Linux on Android

If you’ve made it to this point and haven’t recoiled in horror, great! Here’s what you need to do.

  1. Hook up a regular computer keyboard hooked up to your phone. Don’t try this with the pop-up keyboard your phone has. You’ll tear your hair out. Use something you can type on easily that has a full range of symbols and a regular “enter” key.
  2. Install UserLAnd
  3. Install bVNC if you want a graphical interface, or ConnectBot if you only want command-line. If doing things through VNC, the graphical updates seem to quit if you’re not actively poking at your phone for a while during installations. Go back to the home screen, then back to the viewer to fix this. I had to do this a lot to see if progress was happening.
  4. Open the vnc/ssh app BEFORE you try to use UserLAnd with it the first time. I don’t know why this is needed the first time, but it was necessary for me. On subsequent runs, UserLAnd will be able to invoke the vnc/ssh app even if it’s not running.
  5. Open UserLAnd and set up Debian (I wasn’t able to get the Ubuntu option to work; ssh/vnc couldn’t connect to it).
  6. Open the Debian session. It should invoke the vnc/ssh client. You may need to enter the password you set up in the previous step.
  7. Now the general setup. WARNING: I had to try many of these more than once and so some sudo dpkg calls.
    1. sudo apt-get upgrade
    2. sudo apt-get install lxde

      (if this fails, do it with the –fix-missing flag the next time)

    3. sudo apt-get install haskell-platform
    4. cabal update
    5. ghci

      (testing that the interpreter works; use :q to exit)

If you successfully loaded up the interpreter, congrats – you’ve got Haskell now!

Installing Euterpea on Haskell on Linux on Android

Did you really think it would stop with just Haskell?

If you want Euterpea on top of all this, you are only about half done in terms of setup time investment. One may also wonder about the worthwhileness of doing it, since you can’t use the “play” function. However, you can write MIDI files, and it is possible to develop with Euterpea that way.

Installing the Euterpea library after that was, from my experience, not as simple as a one-line cabal install. I found that, to avoid crashes, each of Euterpea’s dependencies had to be downloaded and installed manually. You will eed to do the following four commands where X and X-version are the package name and version details:

cabal get X
cd X-version
sudo cabal build --v
sudo cabal install --v --global

The verbose flag (–v) helps to show that it’s actually working and hasn’t stalled. Because the setup is slower than normal, I wanted as much indication of progress as possible. The build and install steps must also succeed without a crash. If you get a server timeout or a vnc/ssh disconnect, you’ll have to start over. If the build fails, you will need to do

sudo cabal clean

on the library before building again.

Given that you won’t have the ability to use Euterpea’s “play” command, you may wish to use EuterpeaLite – a stripped down version for MIDI file-writing that I recent put on GitHub for the purpose of being used in situations where either a different back-end is desired or device compatibility issues with the dependencies (the PortMidi and arrows libraries run into this sometimes). If you use EuterpeaLite, you need to perform the steps above for the following libraries:

  1. heap (general requirement for Euterpea)
  2. HCodecs (general requirement for Euterpea)

You can then install EuterpeaLite from GitHub using:

git clone
cd EuterpeaLite
sudo cabal build --v
sudo cabal install --v --global

If you are using the full version of Euterpea, you still need to manually heap and HCodecs as for EuterpeaLite, but you also need ALSA (required by the PortMidi dependency)…

sudo apt-get install libasound2-dev

…and you need these, each one manually installed with the same 4-step cabal process outlined previously.

  1. PortMidi (required for Euterpea’s MIDI back-end)
  2. lazysmallcheck (required by Stream)
  3. Stream (required by arrows)
  4. arrows (required for Euterpea’s signal processing back-end)
  5. Euterpea (warning: this one is REALLY SLOW – even after you’ve gotten the dependencies ready)


ghc-pkg list

after this to check that Euterpea actually shows up. test that it’s working by doing the following:

import Euterpea
writeMidi "test.mid" $ c 4 qn

If successful, regardless of whether you used EuterpeaLite or full Euterpea, you should see the file test.mid in the directory where you started the interpreter. If the install looked successful but you can’t import EuterpeaLite or Euterpea, try restarting the Debian VM and testing again. My experience was that every install except for full Euterpea showed up without a restart, but Euterpea required a restart. If you were able to successfully write a MIDI file, congrats, you’re done! Well, mostly. You will still need to install some kind of text editor environment like vim, gedit, or nano to edit your code, but those choices are up to you. UPDATE: actually I strongly recommend nano, which is the one I was originally using. Ultimately I had difficulty later trying to install gedit, vim, and a couple others that failed when trying to install some gnome manual that takes too long and times out.



Comments 2

Leave a Reply

Your email address will not be published. Required fields are marked *