[Haskell-cafe] How to set a GHC option for a single module and a specific version of GHC?

Antoine Latter aslatter at gmail.com
Mon Jun 7 20:46:12 EDT 2010


On Sat, Jun 5, 2010 at 3:28 AM, Bernie Pope <florbitous at gmail.com> wrote:
> Hi,
>
> I'm looking for a way to set a GHC compile option on a specific module
> (not every module in the program) but only for a specific version of
> GHC. Ideally within the confines of cabal, and in a portable way.
>
> GHC provides the OPTIONS_GHC pragma, but it does not appear to provide
> a way for the pragma to fire for specific versions of GHC. Also, I
> can't use an #ifdef trick because "File-header pragmas are read once
> only, before pre-processing the file (e.g. with cpp)."
>
> Cabal provides conditional statements and a way to check the version
> of GHC, but I can't see a way to get it to only use certain compiler
> options for a particular module.
>
> In summary, what I really want is a modified version of the OPTIONS_GHC pragma:
>
>   {-# OPTIONS_GHC ==6.12.1 ... #-}
>
> or a way to tell cabal to use certain compiler options for a
> particular module under certain conditions.
>

A not-great work-around is to have this one file in a separate source
directory, and then use a different extra source directory based on
the GHC version (by using an if statement in the package description).

Antoine


More information about the Haskell-Cafe mailing list