I can change haddocks based on a flag if I put the entire block within the CPP conditional branches:
#if SOME_MACRO
-- | Whether SOME_MACRO is true
-- >>> someMacro
-- True
someMacro :: Bool
someMacro = macroVal
#else
-- | Whether SOME_MACRO is true
-- >>> someMacro
-- False
someMacro :: Bool
someMacro = macroVal
#endif
And the documentation looks as you'd expect it to, and doctest
also works as expected.
But that's maintenance nightmare for larger comments or code blocks. On the other hand, this does not seem to work:
-- | Whether SOME_MACRO is true
-- >>> someMacro
#if SOME_MACRO
-- True
#else
-- False
#endif
someMacro :: Bool
someMacro = macroVal
Why is that? Isn't CPP processed before Haddock? I have the intuition that it's because a newline is staying on after the CPP stage, but it's just an intuition