5
votes

Suppose I have a Haskell module named MyModule that imports an external module like this:

import ModuleA hiding (a, b, c)

And I cannot modify this import statement, because the program is not exactly mine.

I wish to link to ModuleA.external_function in the documentation for ModuleA, in the comments above a function called my_function. So the code looks something like this:

-- | my_function makes use of 'ModuleA.external_function'
my_function :: Int -> Int

Using haddock 2.10.0, and running cabal haddock, the link to ModuleA.external_function is generated as dist/doc/html/MyModule/ModuleA.html#v:external_function . However, the problem is that the dist/doc/html/MyModule/ModuleA.html file does not exist.

How can I generate a link to the docs for ModuleA instead, like module-A-package/docs/ModuleA.html#v:external_function. In other words, something similar to what http://hackage.haskell.org/package/text-0.11.2.0/docs/Data-Text.html has for its links to the String type (they link to http://hackage.haskell.org/package/base-4.5.0.0/docs/Data-String.html#t:String)? Bear in mind that I cannot modify the import statement.

Thank you.

1
Your question is a bit unclear. In any case, if you have ModuleA.someFunction in scope then 'ModuleA.someFunction' should work just fine. Looking at your generated path, it seems that ModuleA is in its own directory and in fact you're probably not exporting it. If it's not being exported, Haddock won't generate documentation for it. Not all is lost with that case as you can pass --ignore-all-exports to Haddock. When using cabal haddock, you can use --haddock-options to pass it in. Alternatively, put {-# OPTIONS_HADDOCK ignore-exports #-} in MyModule and see if that does it.Mateusz Kowalczyk

1 Answers

0
votes

To make links to external packages in the Haddock documentation, you need to instruct it where to find the documentation for those packages.

It is done by using the --read-interface Haddock command-line option.

Using your example, it will be :

haddock --read-interface module-A-package/docs/,module-A-package/docs/module-A-package.haddock

The .haddock file is made when generating documentation for the package module-A-package using ----dump-interface Haddock command-line option.

More information can be found on the Haddock documentation or this HaskellWiki page.