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

I noticed that I can return to database compatibility by adding a CPP condition as follows:

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 defining dependencies at the package level (i.e. using something like #if MIN_VERSION_optparse-applicative(0,13,0)), and it's hard for me to find documentation for this GHC function.

I am wondering if something like exists MIN_VERSION_optparse-applicative, and if not, how do the supporting hackage keep the code backward compatible?

+4
source share
1 answer

You can find the macro registered here and here ,

, ; , . , , ,

{-# LANGUAGE CPP #-}

foo :: String
foo = 
#if MIN_VERSION_optparse_applicative(0,13,0)
  "x"
#else
  "y"
#endif
+5

Source: https://habr.com/ru/post/1688615/


All Articles