Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use the cpp MIN_VERSION conditional for a haskell package?

I noticed that I can get backwards compatibility with base by adding a CPP conditional like so:

moo :: Moo
moo = Moo
    { happyMoo = Sound "moo"
#if MIN_VERSION_base(4,9,1)
    , upgradedMoo = Sound "moo"
#endif
    , sadMoo = Sound "moo"
    }

But I get an error when I specify package-level dependencies (ie: using something like #if MIN_VERSION_optparse-applicative(0,13,0)) and I'm having a hard time finding documentation on this GHC feature.

I'm wondering if something like MIN_VERSION_optparse-applicative exists and, if not, how do hackage maintainers keep code backward-compatible?

like image 822
stites Avatar asked Nov 02 '17 16:11

stites


1 Answers

You can find the macro documented here and here.

The issue here is package names get mangled in such macros; in particular, dashes get replaced by underscores. So it should be e.g.

{-# LANGUAGE CPP #-}

foo :: String
foo = 
#if MIN_VERSION_optparse_applicative(0,13,0)
  "x"
#else
  "y"
#endif
like image 56
user2407038 Avatar answered Sep 30 '22 04:09

user2407038