[Haskell-cafe] Conditional code for Haddock

Roel van Dijk vandijk.roel at gmail.com
Wed Jan 20 06:20:55 EST 2010

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?

Ideally I want only have to add the following to my .cabal file:

> haddock-options: -D__DOC__

Roel van Dijk

1 - http://trac.haskell.org/haddock/ticket/78

More information about the Haskell-Cafe mailing list