In addition to documenting the whole declaration, in some cases we can also document individual parts of the declaration.
Class methods are documented in the same way as top level type signatures, by using either the "-- |" or "-- ^" annotations:
class C a where -- | This is the documentation for the 'f' method f :: a -> Int -- | This is the documentation for the 'g' method g :: Int -> a |
Note that in Haddock documentation annotations are first-class syntactic objects that are subject to the same layout rules as other syntactic objects; thus in the example class declaration above the documentation annotations must begin in the same column as the method signatures. If you use explicit layout, then don't forget the semi-colon after each documentation comment (but don't put the semi-colon on the same line as the documentation comment, because it will be interpreted as part of the documentation!).
Constructors are documented like so:
data T a b = -- | This is the documentation for the 'C1' constructor C1 a b | -- | This is the documentation for the 'C2' constructor C2 a b |
or like this:
data T a b = C1 a b -- ^ This is the documentation for the 'C1' constructor | C2 a b -- ^ This is the documentation for the 'C2' constructor |
Record fields are documented using one of these styles:
data R a b = C { -- | This is the documentation for the 'a' field a :: a, -- | This is the documentation for the 'b' field b :: b } data R a b = C { a :: a, -- ^ This is the documentation for the 'a' field b :: b -- ^ This is the documentation for the 'b' field } |
Individual arguments to a function may be documented like this:
f :: Int -- ^ The 'Int' argument -> Float -- ^ The 'Float' argument -> IO () -- ^ The return value |
NOTE: this feature isn't implemented in Haddock 0.2.