The problem is not the C preprocessor per se, but that MIN_VERSION_*
macros are generated by cabal at build time, and so you don't get them in GHCi. If you just want to play with the library without installing it, the path of least resistance would be commenting out the macros, as well as the branches of the CPP conditionals which do not match the version of http-conduit
you currently have (if in doubt, check with ghc-pkg list
).
A marginally more principled hack would be using CPP to check whether you are installing with cabal. Assuming http_conduit >= 1.9.0
it might look like this:
#ifdef CABAL
# if MIN_VERSION_http_conduit(1, 9, 0)
successOrMissing s@(Status sci _) hs cookiejar
# else
successOrMissing s@(Status sci _) hs
# endif
| (200 <= sci && sci < 300) || sci == 404 = Nothing
# if MIN_VERSION_http_conduit(1, 9, 0)
| otherwise = Just $ E.toException $ StatusCodeException s hs cookiejar
# else
| otherwise = Just $ E.toException $ StatusCodeException s hs
# endif
#else
successOrMissing s@(Status sci _) hs cookiejar
| (200 <= sci && sci < 300) || sci == 404 = Nothing
| otherwise = Just $ E.toException $ StatusCodeException s hs cookiejar
#endif
Given your use case, though, I don't think that extra step is worth the trouble.
For the sake of completeness: this answer explains how to use cabal macros in GHCi. Doing that, however, requires running cabal build
at least once.