Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell at a user level

I love coding in Haskell, but often am on a computer where I cannot install software, and which has some restrictions about what you can run. I would like to write Haskell code and test it while on this computer. Does anyone know of version of Haskell, interpreted or compiled, written in Java, JavaScript, Ruby, Python, or another interpreted language available in the default install on a Mac? A standalone version of Haskell which can be installed at the user level works too, but compiling Haskell myself is not an option.

like image 279
Andrew Wonnacott Avatar asked Dec 05 '22 14:12

Andrew Wonnacott


2 Answers

The GHC binary distributions (the ones that come as tarballs, not installers) all can be installed locally trivially easily.

./configure --prefix=$HOME/ghc
make install

Then update your path to include $HOME/ghc/bin

If you want cabal, get the tarball from hackage, then untar it and run bootstrap.sh.

GHC works really well as a local install. In fact, I never use it as a system install.

like image 72
Carl Avatar answered Dec 28 '22 16:12

Carl


I do this on my workstation, too, so that the distribution I'm on (Debian in my case) doesn't suddenly start upgrading stuff without me noticing in a simple apt-get upgrade.

This solution installs a full ghc and haskell-platform as well as ~/.cabal prefix.

First of all, I have a ~/local directory that I use in order to put custom-compiled programs in my home directory. I usually dislike the sudo make install step, because I'm giving some random Makefile root access to my system, and that makes me feel queasy.

Then I download the ghc binary distribution from the ghc site. NOTE that I linked you to 7.4.2. I hear there's some segfault bug on Mac OS X, but I'm not aware of the details. You should check that out or get the newer ghc instead, but be aware that there are many packages on hackage that are not yet fixed to work with 7.6. Also, ignore that "STOP!" warning, you're the 1% who actually want a non-distrib GHC binary.

You can just cd into the ghc directory, then do ./configure --prefix=$HOME/local/haskell or so, followed by make install (no compiling necessary, it's just going to install, not compile.)

At this point, you should add ~/local/haskell/bin to your path. Here's the code that I put in my ~/.zshrc, which will add all ~/local/*/bin directories to your path.

You can then get the Haskell Platform, and do the same ./configure --prefix=$HOME/local/haskell && make && make install dance. This step will need compilation. It means that you will need some header libraries installed. I find the random openGL headers that are necessary particularly annoying.

You can also of course skip haskell-platform, and just download cabal-install directly, then install what you need. You should in any case not forget to add ~/.cabal/bin to your $PATH!

Do a cabal update and you should be good to go.

NOTE: there's one important part that the binary distribution of GHC needs, which can sometimes be a pita on old Linux systems: libgmp. It's linked dynamically against it, and if you get some errors about the shared libgmp not being found on OS X, too, you can… well, ask that question in a comment, and I shall explain how to get there. Basically, you'll have to compile libgmp + deps yourself.

But I don't think that should be a problem on OS X. It's just been a problem on a couple old debian boxes I've tried this on.

like image 26
Aleksandar Dimitrov Avatar answered Dec 28 '22 14:12

Aleksandar Dimitrov