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

Michael Snoyman michael at snoyman.com
Wed Dec 1 04:54:23 CET 2010


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.

This is obviously a personal preference issue, but I try to avoid the
Cabal macros since they don't let my code run outside the context of
Cabal. I often times like to have a test suite that I can just use
with runhaskell, and (unless you can tell me otherwise) I can't run it
anymore.

Also, I think

#if GHC7
...
#endif

is more transparent than a check on template-haskell.

Michael



More information about the Haskell-Cafe mailing list