RFC: "Native -XCPP" Proposal

Stephen Paul Weber singpolyma at singpolyma.net
Wed May 6 15:36:05 UTC 2015


>As you may be aware, GHC's `{-# LANGUAGE CPP #-}` language extension
>currently relies on the system's C-compiler bundled `cpp` program to
>provide a "traditional mode" c-preprocessor.

Yes.  This is one of my favourite things in GHC-land -- that an existing, 
good-enough, standardised, and widely-deployed solution was chosen over 
a NiH reinvention of preprocessing.  This allows other Haskell compilers to 
support CPP on basically any system (since cpp is so standard) without much 
effort, or even if the compiler does not support {-# LANGUAGE CPP -#} the 
user can easily run `cpp` over the source files themselves before feeding 
the source into the compiler.

Because it is a real `cpp` being used, the developmer must take care to 
follow the CPP syntax in the file that will then be transformed into Haskell 
by `cpp` in the same way that C, C++, and other developers have to take 
extra care (especially around use of # and end-of-line \) when using `cpp`, 
but this is the normal state of affairs for a secondary preprocessor step.  
As a benefit, the source code will be processable by standard `cpp` 
implementations available for virtually every platform.

In short, the current solution provides a very robust and portable way to do 
pre-compile preprocessing, and I like it very much.


More information about the ghc-devs mailing list