Haskell


12 posts
by djhuk » Sat May 26, 2012 9:45 pm
I've been trying to get Haskell working for a while now but I think I've eventually cracked it on Arch-Linux

Hopefully the following will help others wishing to run haskell on the 'Pi. Note that the ARM version of GHC currently does not support GHCI.

To install you simply need to do the following

Code: Select all
sudo pacman -S ghc


If you get an error when attempting to compile a haskell source file

Code: Select all
[daniel@alarmpi ~]$ ghc test.hs -o test
ghc: could not execute: /usr/lib/distcc/bin/gcc


Then you will need to install distcc

Code: Select all
sudo pacman -S distcc


and finally


Code: Select all
[daniel@alarmpi ~]$ ghc test.hs -o test
[daniel@alarmpi ~]$./test
Hello world!
Posts: 20
Joined: Fri May 25, 2012 5:54 pm
by antiloquax » Sun Jun 03, 2012 5:24 am
Thanks djhuk, I will try this later.
I like this tutorial.
Learn You a Haskell
Posts: 406
Joined: Sun Nov 20, 2011 11:37 am
by shapr » Wed Jun 06, 2012 8:33 pm
I've installed the debian image on my raspberry pi, and it has ghc6 debs available...
But I'd like to use ghc 7.4.1, does anyone know if there's an apt source available for ghc 7.4.1 on armel?

Thanks,

shapr on #haskell
Posts: 3
Joined: Thu May 31, 2012 4:01 pm
by djhuk » Wed Jun 20, 2012 9:17 pm
shapr wrote:I've installed the debian image on my raspberry pi, and it has ghc6 debs available...
But I'd like to use ghc 7.4.1, does anyone know if there's an apt source available for ghc 7.4.1 on armel?

Thanks,

shapr on #haskell


Hi shapr, so I've been looking into this after getting annoyed with 6.12.3!

On the wheezy sources of Debian you can install GHC 7.4.1 on your system and (so far) everything seems to work OK except GHCI - which doesn't work with ARM anyway. I haven't actually tested it on the Pi, I'm running it through QEMU as I don't want to replace my installation of Arch on my 'Pi.

I'm not sure how to get 7.4.x installed on Arch Linux unfortunately, and building GHC from scratch on the Pi is a non-starter as the memory on the device is too low.

So my current "solution" is to

a) Write haskell programs on my Mac
b) Start up a VM with ubuntu running on it
c) Inside the VM start an instance of QEMU to emulate an ARM processor and boot the debian image
d) Inside the VM and then inside the QEMU ARM VM retrieve my haskell code from my mac and compile it into an executable
e) Transfer this via SSH to my Pi and run the code

Arduous process but it works!
Posts: 20
Joined: Fri May 25, 2012 5:54 pm
by djhuk » Fri Jun 22, 2012 8:43 pm
I think there is still a lot of work to do here.

Unfortunately the problem with my method above is....it runs into a stumbling block when you attempt to compile a program with a haskell library you don't have on your machine. Installing cabal is fine but say if you do a quick "cabal install network", you'll run into problems after about 20 minutes because the device will run out of memory.

I'm trying to search desperately for a way to make QEMU boot the ARM image with more than 256mb of RAM but all indicators are pointing to the fact that only 256mb is supported.
Posts: 20
Joined: Fri May 25, 2012 5:54 pm
by djhuk » Sun Jul 01, 2012 4:42 pm
Some updates on this.

So as we know already
  • The current available distributions of Linux available to the Pi, Arch Linux and Debian offer version 6 of GHC which is years out of date
  • Updating the source repository on the debian installation to "wheezy" will give you GHC version 7.4.1
  • The memory limit (256mb) on the Pi means that it's very difficult to compile large projects or use Cabal effectively, especially when retrieving and compiling large libraries such as Parsec or Network. The compiler will crash after a while as it runs out of memory
This means that the only viable option for compiling large projects is to compile them on a separate, more powerful machine and transfer the binaries across to your Pi. The problem is you cannot cross compile x86 to target an ARM platform (GHC is not a cross compiler)

So effectively the only option you have left is to either purchase a more powerful ARM based device (beagleboard? only slightly more RAM than the Pi....) or use QEMU to emulate an ARM computer. I chose the latter option, but as described in my previous post, there is an issue with the fact that the "versatilepb" machine type expressed in most Pi-QEMU tutorials is limited to 256mb.

To get round this I spent a while hacking about until I was able to boot the R-PI version of debian with 1024MB of ram using the options
Code: Select all
-M vexpress-a9 -cpu cortex-a9
and a few kernel bits and pieces gathered from various websites. After expanding the .img and booting into the system I was able to install LLVM-3.0, GHC-7.4.1 and GCC-4.6.3 and then I embarked on the long, arduous path of compiling GHC-7.4.2 which took 5 days to complete, although I suspect my Mac was erroneously going into sleep mode for some of that period.

After that completed and installed, my QEMU ARM VM was able to run GHC-7.4.2 and I could install cabal and all the libraries I needed without much issue and eventually, I was able to compile some haskell applications and transfer the binaries to my Pi accordingly.

Some observations: -

  • GHCI is supposed to be working on ARM in GHC7.4.2 but it crashes on mine at the moment.
  • I transferred the GHC 7.4.2 binaries and libraries to my Pi (running arch linux) and they run OK but I can't seem to compile apps directly on the Pi because I don't know how to get LLVM-3.0 on arch linux arm (pacman only seems to install 3.1 - which has been reported to have issues with GHC). Compiling LLVM-3.0 from source is out of the question because of the memory limitations
  • Binaries that you compile on ARM seem to be significantly larger than those generated for x86 architectures
Posts: 20
Joined: Fri May 25, 2012 5:54 pm
by djhuk » Tue Jul 03, 2012 8:20 pm
So I've gone back to using 7.4.1 again after too many issues with the 7.4.2 branch.

The downside to playing with 7.4.1 is the fact that GHCi isn't supported on ARM architectures. This is a real bummer if you want to install something like the SNAP framework http://snapframework.com/

One of the dependencies of Snap is the vector-0.9.1 library, unfortunately compilation of this fails because it requires GHCI

Code: Select all
[ 5 of 30] Compiling Data.Vector.Fusion.Stream.Monadic ( Data/Vector/Fusion/Stream/Monadic.hs, dist/build/Data/Vector/Fusion/Stream/Monadic.o )
ghc: panic! (the 'impossible' happened)
  (GHC version 7.4.1 for arm-unknown-linux):
   Cant do annotations without GHCi
    {Data/Vector/Fusion/Stream/Monadic.hs:104:19-33}
    base:GHC.Exts.ForceSpecConstr{d r8sZ}
Posts: 20
Joined: Fri May 25, 2012 5:54 pm
by djhuk » Sun Jul 08, 2012 8:06 pm
Another thing I have noticed is the binaries that GHC will produce are A LOT larger than their x86 counterparts, which might be an issue if the memory card on your Pi is low on space.

Although a call to the "strip" tool does seem to reduce the size with no ill effects.
Posts: 20
Joined: Fri May 25, 2012 5:54 pm
by shapr » Thu Aug 09, 2012 11:19 pm
djhuk wrote:
  • GHCI is supposed to be working on ARM in GHC7.4.2 but it crashes on mine at the moment.


Are your GHC 7.4.2 binaries available online somewhere?
I'd like to report any issues to the GHC maintainers.
I tried to build haskell-platform on my Pi, and gave up after five hours or so.
Posts: 3
Joined: Thu May 31, 2012 4:01 pm
by jackokring » Thu Aug 09, 2012 11:35 pm
haskell has some of ocaml inside, or vice versa. What are the main differences?

Cheers Jacko
Pi=B256R0USB CL4SD8GB Raspbian Stock. https://sites.google.com/site/rubikcompression/strictly-long https://dl.dropboxusercontent.com/u/1615413/Own%20Work/Leptronics.pdf https://groups.google.com/forum/#!topic/comp.compression/t22ct_BKi9w
User avatar
Posts: 773
Joined: Tue Jul 31, 2012 8:27 am
Location: London, UK
by pbv » Sat Sep 01, 2012 12:20 am
Haskell http://www.haskell.org and O'Caml http://caml.inria.fr/ are distinct languages with separate implementations. The only connection is that both are statically typed and employ automatic type inference that started in ML back in the 70s. O'Caml is slighter older and is a more "pragmatic" design (call-by-value that allows impure side-effects such as I/O anywhere). Haskell is a more "mathematical" language (pure-by-default with side-effects controlled by an abstraction called monads).
Both allow higher-levels and safer programming that imperative or OO languages; plus both have high performance implementations that compete with C++ and Java and are at least an higher of magnitude faster than scripting languages such as Python, Perl, Ruby,etc.
Posts: 3
Joined: Fri Aug 31, 2012 1:27 pm
by pbv » Sat Sep 01, 2012 3:21 pm
I received my Pi just a few days and being a Haskell programmer thought I'd share my experience so far. I'm running Debian wheezy ("raspbian") on a Sandisk 8GB Class 10 card.

There is a Haskell interpreter called Hugs (the debian package is "hugs") ; this is fine for learning or quick experimentation. There is also an optimizing compiler called GHC (package "ghc"); this requires more resources (both to install and run) but generates faster native ARM binaries that do not require the compiler/interpreter to run. On x86 GHC also includes its own interpreter (called ghci) but unfortunately this isn't (yet) available for the ARM architecture. There are also many development libraries some written in Haskell, other bindings to various C/C++ libraries. There is a blessed set of libraries and tools (package "haskell-platform"). Installing GHC plus the platform will require about 300 MB.

After a few toy examples, successfully compiled my HsTZAAR implementation of a modern boardgame with AI and a GTK user-interface (check the link here http://www.dcc.fc.up.pt/~pbv/stuff/hstzaar). Compiling took about 10 mins which is at least 10x slower than my linux x86 laptop. GHC also requires a lot of memory so I recommend compiling from the console (no X) and configuring the memory split as 240/16.
However, the compiled executable is much more frugal: runs under X rather than the console, the interface is responsive and so is the AI (at least at lower search levels). Inspecting with top shows that it uses at most 16Mb of resident memory (actually very similiar to the x86 version).

So the moral of the story is: I am impressed that Haskell runs so well on the little Pi! I woudn't want to use it as a development machine simply because of the slow compilation, but porting existing code should work well (subject to the usual caveats of available resources, etc).
Posts: 3
Joined: Fri Aug 31, 2012 1:27 pm