[Haskell-cafe] Conditional compilation for different versions of
GHC?
Antoine Latter
aslatter at gmail.com
Sun Nov 28 04:16:05 CET 2010
On Sat, Nov 27, 2010 at 8:38 PM, Jinjing Wang <nfjinjing at gmail.com> wrote:
> Hi Michael, you are absolutely correct, cabal did set the flags automatically.
>
> To sum up, here's what needs to be done:
>
> * add `flag ghc7` as a field in cabal
> * add:
>
> if flag(ghc7)
> build-depends: base >= 4.3 && < 5
> cpp-options: -DGHC7
> else
> build-depends: base >= 4 && < 4.3
>
> in library field in cabal
>
> * add `{-# LANGUAGE CPP #-}` in source file
> * add
>
> #if GHC7
> x
>
> #else
> y
>
> #endif
>
>
> Hi Antonine, I don't know how to not set those fields in the
> constructor.. as a QQ noob, I'm just hacking on some legacy code. This
> code doesn't compile in GHC7, so I have to do this trick.
>
> * https://github.com/nfjinjing/mps/blob/master/src/MPS/TH.hs
>
Something like:
myQuoter = QuasiQuoter {
quoteExp = expQuoter,
quotePat = patQuoter
}
Will work in either version, but it will leave the un-set fields set
to `undefined`, so you'll get a compile error if you try to use them.
I haven't tested this, but I've done it with other record types.
Take care,
Antoine
More information about the Haskell-Cafe
mailing list