This script allows you to easily switch between different versions of GHC (the Glasgow Haskell Compiler) that are installed on your system. It's a simple Bash script that manipulates a symlink pointing to a subdirectory with the current preferred version of the GHC binaries.
-
Install the Haskell Platform (HP) for Mac OS X.
The HP creates a directory
/Library/Frameworks/GHC.frameworkwith all the tools needed to use Haskell. In particular, theVersionssubdirectory contains the GHC installation. Each future installation of HP adds a new version in a subdirectory ofVersions.In
Versions, there is a symlinkCurrentthat points to the subdirectory with the "current" GHC. We use that to determine which GHC we want to use at any one point in time. -
Update the HP symlinks in
/usr/binto useCurrent.To make the HP tools part of the standard path, the HP installer creates symlinks in
/usr/binthat point to the binaries in the current version. By default, they may link to the specific subdirectory inVersions. You should relink them, replacing the specific version withCurrent.You can find the current symlinks with
ls -l /usr/bin/ | grep GHC\.framework. For example, I seeghc,ghc-pkg,ghci,hp2ps,hpc,hsc2hs,runghc, andrunhaskell, among others. There may also be version-specific ones likeghc-7.4.1which you may want to delete, since they will not be applicable if you change your current version.For each symlink
$Ffrom above, recreate it withsudo ln -sf /Library/Frameworks/GHC.framework/Versions/Current/usr/bin/$F /usr/bin/$F -
Put
ghc-verin your$PATH.
And you're done!
-
Use
ghc-ver listto see the versions available.It simply looks at the subdirectories in
/Library/Frameworks/GHC.framework/Versionsand gives you the list of names. Thus, it helps to name the versions appropriately and concisely. -
Use
ghc-ver 7.4.1to select version7.4.1if it is available. You will get a notice if it is not, and you will also get a confirmation of the current GHC version, which should be unchanged in the case of failure. -
Install any future versions of the HP as normal. Unless the installer changes, you should just be able to switch to the new version using
ghc-ver. (You may need to update the/usr/binsymlinks as described above.) -
Install any non-HP versions of GHC in
/Library/Frameworks/GHC.framework/Versions.In the case where you are compiling GHC from source, say the version is called
HEAD, you can create the directory/Library/Frameworks/GHC.framework/Versions/HEADand configure GHC as follows:./configure \ --prefix=/Library/Frameworks/GHC.framework/Versions/HEAD/usr \ --with-gmp-libraries=/Library/Frameworks/GMP.framework \ --with-gmp-includes=/Library/Frameworks/GMP.framework/HeadersThen,
sudo make installwill do the right thing.You may or may not need the extra
GMP.frameworkflags. There have be times in the past where GMP did not work properly when compiling GHC from source.