[Haskell-cafe] Cabal and more than one version

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Tue Nov 18 16:30:05 EST 2008

On Tue, 2008-11-18 at 01:48 -0800, Jason Dusek wrote:
> I'd like to be able to do something like:
>     if (template-haskell < 2.3)
>       cpp-options: -D TH_THE_YOUNGER
>     else
>       cpp-options: -D TH_THE_ELDER
>   I guess this kind of thing is not possible at present?

It is possible, in two different ways.

The easiest way is that if you're using Cabal-1.6 then it provides cpp
macros to test the version number of packages you're using. 

#if MIN_VERSION_template_haskell(2,3,0)

The alternative that works back to Cabal-1.2 is to use:

flag newer-th

  if flag(newer-th)
    build-depends: template-haskell >= 2.3
    cpp-options: -D TH_THE_ELDER
    build-depends: template-haskell < 2.3
    cpp-options: -D TH_THE_YOUNGER

See also ticket http://hackage.haskell.org/trac/hackage/ticket/209 for a
proposal to add syntactic sugar similar to the syntax you first


More information about the Haskell-Cafe mailing list