New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CPP macros suitable for partial evaluation #9329
Comments
Few comments, it's also GHC which defines {-# LANGUAGE CPP #-}
main :: IO ()
#if MIN_VERSION_base(4,19,0)
main = print True
#else
main = print False
#endif we have
I don't know (or remember) why GHC defines them. Would be get to find out, and check if you'd also like/need to change GHC. I'd prefer #define SUPER_VERSION_base 4
#define MAJOR_VERSION_base 19
#define MINOR_VERSION_base 0
#define PATCH_VERSION_base 0 just because I likes justified identifiers :P I'd appreciate if changes to |
And not having new features of This is a reason why I think that Specifically, if something in |
I was able to make this work by:
In the end I did something like this to remove all
|
I couldn't figure out a nice way to deal with |
The same trick with replacing particular comparisons with a constant would work, though, if the form is consistent enough in your codebase. |
I looked into tools that could simplify my codebase by partially evaluating CPP conditionals.
E.g. if I have
and I no longer support GHC < 8.6 or base < 4.11 then I can get rid of some cruft by partially evaluating the conditions and throw away the conditional together with the branch that is now impossible..
I checked some tools that do some partial evaluation of CPP conditionals:
unifdef
(shipped on my system macOS): https://dotat.at/prog/unifdef/cppp
: https://www.muppetlabs.com/~breadbox/software/cppp.htmlcoan
: https://coan2.sourceforge.net/index.phpThese tools typically only support setting a symbol to a value, like
__GLASGOW_HASKELL__=806
. They do not accept predicates, i.e., I cannot setMIN_VERSION_base(4,11,0)
to be true.So if Cabal defined 3 separate symbols to specify a version, instead of a ternary predicate, this would be compatible with such tools.
This would be usable in Haskell code as such:
(One could think of other macro names, like the triple
VERSION_EDITION_base
,VERSION_MAJOR_base
,VERSION_MINOR_base
---although the terminology edition for the "major-major" version is not established.)The text was updated successfully, but these errors were encountered: