I use haddock and don't want all of my exported functions to be displayed in the documentation. Is it possible to hide specific functions? I found the prune attribute at http://www.haskell.org/haddock/doc/html/module-attributes.html, but this is not what I want since some functions which shall be exported don't have a documentation annotation.
-
If you're exporting a fuction, why wouldn't you want it listed in the documentation? – jwodder Jun 02 '13 at 20:44
-
This function is of no use for someone who wants to use this module. However, I need this function in a module for testing and I don't want to copy and paste the source code to this testing module. – efie Jun 02 '13 at 20:58
-
2Maybe you could move the code to a hidden module. Then the public module (exposed in cabal terms) and the testing module can both import that module, and the exposed module can hide specific functions by simply not re-exporting them. – raymonad Jun 02 '13 at 21:36
-
Thank you raymonad, this would be a solution. However this function does not belong to any other module semantically, so I'd still prefer a solution which hides this function from the documentation, it it exists. – efie Jun 02 '13 at 21:59
-
1The fact that you're exporting a name alone has effect on the user of your module, since they won't be able to use the same name without explicitly excluding it from the import. In fact, this is good reason to use raymonad's hidden module approach. – Michał Marczyk Jun 02 '13 at 22:57
2 Answers
Assuming your current module is Foo.Bar
, one solution would be to break it up into Foo.Bar
and Foo.Bar.Internal
. You could move all the definitions related to the function you don't want to export--perhaps even all the definitions--into Foo.Bar.Internal
. Then, in Foo.Bar
, you would re-export only the definitions you want the world to see.
This approach has a couple of advantages. It lets you export everything you need, while still giving the user a clear sign that certain things shouldn't be used. It also lets you document your special functions inside the Internal
module, which is going to be useful (if only for your future self :P).
You could simply not export Foo.Bar.Internal
in your .cabal
file, hiding it from the world. However, this is not necessarily the best approach; look at the answers to How, why and when to use the ".Internal" modules pattern?, in particular luqui's.

- 1
- 1

- 67,485
- 18
- 177
- 214
Another possibility is to make a module Foo.Bar.Hidden
exporting all of the stuff you want to hide, and then re-export the whole Foo.Bar.Hidden
module from Foo.Bar
:
module Foo.Bar (
blah1,
blah2,
blah3,
module Foo.Bar.Hidden
)
where
import Foo.Bar.Hidden
blah1 = ...
blah2 = ...
blah3 = ...
This way, the hidden stuff will be exported from Foo.Bar
, but not included in the documentation. The documentation will only include one relatively unobtrusive link to the Foo.Bar.Hidden
module as a whole.

- 148
- 3