Search code examples
haskellhaddock

How to reduce documentation duplication using Haddock


I have two very similar functions and both need exactly the same documentation. Is there a way in Haddock to avoid comment duplication?

I could not find description of this feature in Haddock documentation, but I guess there is a way to do so.

For instance in Javadoc there is {@inheritDoc} and @see SomeClass#someMethod(). What about Haddock?


Solution

  • Unfortunately, it is not possible for function declarations to have reusable documentation with Haddock at the moment. Here is an issue tracking this.

    The -- $chunk_name documentation chunk naming is only available for module documentation, i.e for the export section. This is only handy for moving documentation from the top of the module to the bottom to reduce the clutter.

    Common workarounds for this problem are:

    • make sure the similar function is in scope an add this to documentation: -- | See `functionName`. OR -- | See 'functionName'.
    • or manually copy and paste documentation if it is small enough, similarly how it is done in bytestring and vector packages.