I was fighting with Haskell last weekend. At first, I couldn't install some missing libraries with Cabal, and then, when trying to find out what's wrong, I ended up removing the whole Haskell installation — only to find out I could no longer install neither the Haskell Platform nor even just Cabal Install! The warnings I would see were more or less about the use of the single quote in source code:
Preprocessing library text-0.11.2.3...
Data/Text.hs:6:52:
warning: missing terminating ' character [-Winvalid-pp-token]
-- Copyright : (c) 2009, 2010, 2011, 2012 Bryan O'Sullivan,
^
The errors that finally prevented the installation, were about having non-preprocessor-directive lines start with #
in Haskell files that should be preprocessed with the C preprocessor (CPP):
Data/Text.hs:442:3:
error: invalid preprocessing directive
#-}
(I should mention here, by the way, that Clang is all correct in rejecting these source files: it's trying to protect poor coders from writing e.g. #elsif
where #elif
would be needed! It's just that Haskellers are used to a less strict version of the C preprocessor, one that's been supported by the GNU compiler since ages ago.)
I copied both the above warnings and the error from the Haskell text
package bug report haskell/text#53, but similar problems have been previously cited in the GHC bug tracker as well as Homebrew bug tracker about cabal-install
.
I asked about the problem in the #haskell
IRC channel but I'm unsure where the source of this problem should be actually fixed:
- a) in broken packages (i.e. by moving the closing pragma markers,
#-}
, to the end of the preceding line), - b) in the Homebrew formulas (in that case, I guess it would be best to fix the GHC formula), or
- c) in GHC itself, to make it not use the current C compiler for preprocessing Haskell source files (there's a Haskell implementation of the CPP in http://hackage.haskell.org/package/cpphs-1.16 but some commenters in IRC were concerned about the LGPL-mode licensing.)
So before we'll find a satisfactory permanent solution, here's my quick interim fix for the problem.
…with Homebrew and a very recent version of Clang.
-
Install Glasgow Haskell Compiler 7.6.3. (This would be installed by
brew install haskell-platform
anyway, but we need it before that.)brew install ghc
-
Enable installation of GCC versions, and install e.g. gcc-4.7.
brew tap homebrew/versions brew install gcc47
-
GHC uses
/usr/bin/gcc
by default, which is actually Clang. And apparently, new Clang versions don't support the-traditional
GCC option that makes the C preprocessor work in a friendly manner to Haskell files. So, instead of using Clang as the preprocessor, reconfigure the GHC compiler script to compile with/usr/local/bin/gcc-4.7
instead.nano /usr/local/Cellar/ghc/7.6.3/lib/ghc-7.6.3/settings
(In the above file, replace the second line:
("C compiler command", "/usr/bin/gcc"),
with:
("C compiler command", "/usr/local/bin/gcc-4.8"),
-
Now you should be good to install Haskell Platform – or just
cabal-install
if that's what you like.brew install haskell-platform
This should now work out with reasonably few problems, warnings or errors.
(At least, I'm keeping my fingers crossed!)
— @pyrtsa, 2013-08-12.
There's an easier solution to this: install XCode's Command Line Tools for Version 4.6.x (preferably 4.6.2 form April 2013) from the apple developer's website. This fix is much faster and is much much easier to implement. You may want to add something about this.