
Am Mittwoch 20 Januar 2010 12:20:55 schrieb Roel van Dijk:
I want to generate documentation for the following code snippet:
import qualified Data.ByteString as BS ( ByteString, length )
-- | Foo 'BS.empty' equals 0 foo ∷ BS.ByteString → Int foo = BS.length
Because I do not explicitly import BS.empty haddock will not generate a nice link.
I can fix it by adding:
import qualified Data.ByteString as BS ( empty )
But now the compiler rightly warns me:
Warning: Imported from `Data.ByteString' but not used: `BS.empty'
There is a ticket related to this problem [1], but I do not think making haddock 'magically' find BS.empty is the right answer. What I would like to
do is:
#ifdef __DOC__ import qualified Data.ByteString as BS ( empty ) #endif
Because I use additional symbols in my comments it feels natural to also have special imports for them.
I know that cabal used to define the __HADDOCK__ macro. Is it possible to manually define a preprocessor macro when haddock is run? Perhaps an equivalent to ghc-options: haddock-options?
Doesn't haddock define __HADDOCK__ by itself? I would've thought import qualified Data.ByteString as Bs ( ByteString , length #ifdef __HADDOCK__ , empty #endif ) should work.
Ideally I want only have to add the following to my .cabal file:
haddock-options: -D__DOC__
Regards, Roel van Dijk