[Haskell-cafe] RFC: "Native -XCPP" Proposal

wren romano winterkoninkje at gmail.com
Fri May 8 03:45:48 UTC 2015


On Wed, May 6, 2015 at 9:05 AM, Alan & Kim Zimmerman
<alan.zimm at gmail.com> wrote:
> Perhaps it makes sense to scan hackage to find all the different CPP idioms
> that are actually used in Haskell code, if it is a small/well-defined set it
> may be worth writing a simple custom preprocessor.

Conditional imports are far and away the most commonly used idiom.
Second most common, I'd say, is specifying GHC-specific vs
compiler-generic implementations of top-level functions (e.g., using
GHC.Exts.build or not). For both of these it's sufficient to have the
#if construction plus everything needed for the conditional
expressions.

However, while the #if construction covers the vast majority of use
cases, it doesn't cover all of them. Macros are also important. For
example, a number of low-level libraries will use macros for things
like having assertions which are either compiled as runtime checks, or
as nothing, depending on a Cabal flag. Of course, there are plenty of
other places where we want to use macros in low-level code, either to
force inlining, or to have conditional compilation of (non-top-level)
expressions that show up over and over. That these idioms aren't more
common is just because there aren't more people working on such
low-level code.

In theory TH should be able to handle this stuff, but TH is a verbose
sledgehammer for these sorts of problems, and using TH means
restricting yourself to being GHC-only.

-- 
Live well,
~wren


More information about the Libraries mailing list