[Haskell-cafe] cpp question

Brandon Allbery allbery.b at gmail.com
Sun Feb 1 21:51:34 UTC 2015


On Sun, Feb 1, 2015 at 4:42 PM, S. Doaitse Swierstra <doaitse at swierstra.net>
wrote:

> With the new version of GHC (7.8.3) I am running into problems with cpp.
>
> The header of one of the files of my uu-parsinglib library reads as
> follows:
>
> {-# LANGUAGE NoMonomorphismRestriction,
>              RankNTypes,
>              FlexibleContexts,
>              CPP  #-}
> #define DEMO(p,i) demo "p" i p
> #define DEMOG(p,i) demo "p" i (mkP (p))
> module Text.ParserCombinators.UU.Demo.MergeAndPermute where
>
> ...
>
> However when I try to compile this file I get error messages like:
>
> Text/ParserCombinators/UU/Demo/Demo.hs:88:17:
>     Not in scope: data constructor ‘DEMOG’
>

(1) ghc is at 7.8.4. I *think* 7.8.4 does slightly better here, but only
slightly:

(2) May I guess that Demo.hs line 88 starts with an identifier with a prime
in it? GHC 7.8.3 on OS X tries to make clang's cpp behave like gcc's, but
does not completely succeed; clang's cpp will ignore macros in what it
thinks are quoted strings/chars, so fails when faced with things like

    foo' = ... something using a cpp macro here ...

One workaround is to install ghc from MacPorts (forces gcc's cpp) or the
github ghcformacosx repo (which I think is Homebrew-based? so it depends on
how much you like code with no error checking to speak of and curl-pipe-sh
"hack me please" installation).

7.8.4 may also provide some way to point cpp to "gcc --traditional -E".
Long term, we need to move away from using a C preprocessor for Haskell
code; there are no guarantees that it won't try to enforce C syntax on you,
like clang's does.

-- 
brandon s allbery kf8nh                               sine nomine associates
allbery.b at gmail.com                                  ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20150201/3a54c788/attachment.html>


More information about the Haskell-Cafe mailing list