Issue tracker for Haskell documentation projects for Bay Area haskell group meetup.
Most Haddock syntax involves a comment followed by some sort of "control character" based on what kind of documentation you're writing. Here's a brief overview of some basic concepts (full guide available here).
Top-level declarations like functions and data
declarations can be documented by putting -- |
on the line before declaration:
-- | Opens the cave where the treasure is.
openSesame :: IO ()
openSesame = ...
This syntax (-- |
) also works for data
declarations, newtype
, type
,
If you reference another function or data type, wrap it in single quotes to have Haddock hyperlink to it:
-- | This function calls 'openSesame' and does some other things
openSesame2 :: IO ()
openSesame2 = ...
See the Haddock Guide for a concise explanation.
As the guide explains, you can use bird tracks (>) before each line, or surround the code block with @
symbols. Bird tracks are simpler, because you don't need to escape Haddock markup:
-- | This function reverses a string
--
-- > let x = reverse "abc"
-- > x == "cba" -- True
Writing examples using @
signs is more powerful, because you can do things like link to other functions from the code block. You'll need to escape Haddock markup, though. You can see this approach being used here
Sometimes you'll have a group of functions that you'd like to give a broader explanation for. You can create a block of Haddock documentation with an identifier:
-- $example
-- Here I give a high level overview of these functions, and provide some example code.
and then reference it in the export list:
module Yesod.Form.Bootstrap3
( -- * Example: Rendering a basic form
-- $example
-- * Rendering forms
renderBootstrap3
You can see an example of this being done in this module.
Again, the full Haddock guide is available here.