[Haskell-cafe] Conditional compilation for different versions of GHC?

Duncan Coutts duncan.coutts at googlemail.com
Tue Dec 14 00:24:29 CET 2010


On 1 December 2010 03:54, Michael Snoyman <michael at snoyman.com> wrote:
> On Wed, Dec 1, 2010 at 4:07 AM, Thomas Schilling
> <nominolo at googlemail.com> wrote:
>> I think a nicer way to solve that issue is to use Cabal's MIN_VERSION macros.
>>
>>  1. Add CPP to your extensions.  This will cause cabal to
>> auto-generate a file with MIN_VERSION_<pkg> macros for each <pkg> in
>> build-depends.
>>
>>  2. GHC 6.12.* comes with template-haskell 2.4, so to test for that use:
>>
>> #ifdef MIN_VERSION_template_haskell(2,4,0)
>>  .. ghc-6.12.* code here.
>> #endif
>>
>> This should make it more transparent to the user.

> Also, I think
>
> #if GHC7
> ...
> #endif
>
> is more transparent than a check on template-haskell.

Note that in many cases it is inappropriate to use the ghc version as
a proxy for a library version since most libraries are upgradable
independently of GHC.

Duncan



More information about the Haskell-Cafe mailing list