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

Michael Snoyman michael at snoyman.com
Sat Nov 27 18:32:16 CET 2010


On Sat, Nov 27, 2010 at 6:59 PM, Jinjing Wang <nfjinjing at gmail.com> wrote:
> Dear list,
>
> >From ghc 7.0.1 release notes:
>
>> The Language.Haskell.TH.Quote.QuasiQuoter type has two new fields: quoteType and quoteDec.
>
> Some of my code needs to be conditionally compiled to support both
> version 6 and 7, what is the recommended way to do it?
>
> ref:
>
> * http://new-www.haskell.org/ghc/docs/7.0.1/html/users_guide/release-7-0-1.html

Hi Jinjing,

I've done this in Yesod. I'm not sure if it's the best way, but
basically I've added a ghc7 flag to the cabal file, and a block for
the library that reads:

    if flag(ghc7)
        build-depends:   base                      >= 4.3      && < 5
        cpp-options:     -DGHC7
    else
        build-depends:   base                      >= 4        && < 4.3

Then whenever I want to quasi-quote in the code, I write:

#if GHC7
    [quasiquoter|
#else
    [$quasiquoter|
#endif

Michael


More information about the Haskell-Cafe mailing list