Haddock understands certain textual cues inside documentation annotations that tell it how to render the documentation. The cues (or “markup”) have been designed to be simple and mnemonic in ASCII so that the programmer doesn't have to deal with heavyweight annotations when editing documentation comments.
The following characters have special meanings in
<. To insert a literal occurrence of
one of these special characters, precede it with a backslash
Additionally, the character
a special meaning at the beginning of a line, and the
following characters have special meanings at the beginning of
-. These characters
can also be escaped using
Furthermore, the character sequence
has a special meaning at the beginning of a line. To
escape it, just prefix the characters in the sequence with a
Although Haskell source files may contain any character
from the Unicode character set, the encoding of these characters
as bytes varies between systems, so that only source files
restricted to the ASCII character set are portable. Other
characters may be specified in character and string literals
using Haskell character escapes. To represent such characters
in documentation comments, Haddock supports SGML-style numeric
character references of the forms
are decimal and hexadecimal numbers denoting a code position
in Unicode (or ISO 10646). For example, the references
λ all represent the lower-case
Displayed blocks of code are indicated by surrounding a
@...@ or by preceding each
line of a paragraph with
> (we often
call these “bird tracks”). For
-- | This documentation includes two blocks of code: -- -- @ -- f x = x + x -- @ -- -- > g x = x * 42
There is an important difference between the two forms
of code block: in the bird-track form, the text to the right
of the ‘
>’ is interpreted
literally, whereas the
interprets markup as normal inside the code block.
Haddock has markup support for examples of interaction with a
read-eval-print loop (REPL). An
example is introduced with
>>> followed by an expression followed
by zero or more result lines:
-- | Two examples are given bellow: -- -- >>> fib 10 -- 55 -- -- >>> putStrLn "foo\nbar" -- foo -- bar
Referring to a Haskell identifier, whether it be a type, class, constructor, or function, is done by surrounding it with single quotes:
-- | This module defines the type 'T'.
If there is an entity
T in scope in
the current module, then the documentation will hyperlink the
reference in the text to the definition of
T (if the output format supports
hyperlinking, of course; in a printed format it might instead
insert a page reference to the definition).
It is also possible to refer to entities that are not in scope in the current module, by giving the full qualified name of the entity:
-- | The identifier 'M.T' is not in scope
M.T is not otherwise in scope,
then Haddock will simply emit a link pointing to the entity
T exported from module
(without checking to see whether either
To make life easier for documentation writers, a quoted identifier is only interpreted as such if the quotes surround a lexically valid Haskell identifier. This means, for example, that it normally isn't necessary to escape the single quote when used as an apostrophe:
-- | I don't have to escape my apostrophes; great, isn't it?
For compatibility with other systems, the following
alternative form of markup is accepted:
Emphasis may be added by surrounding text with
Monospaced (or typewriter) text is indicated by
surrounding it with
@...@. Other markup is
valid inside a monospaced span: for example
@'f' a b@ will hyperlink the
f inside the code fragment.
Linking to a module is done by surrounding the module name with double quotes:
-- | This is a reference to the "Foo" module.
A bulleted item is represented by preceding a paragraph
with either “
-”. A sequence of bulleted
paragraphs is rendered as an itemized list in the generated
-- | This is a bulleted list: -- -- * first item -- -- * second item
An enumerated list is similar, except each paragraph
must be preceded by either
n is any integer. e.g.
-- | This is an enumerated list: -- -- (1) first item -- -- 2. second item
Definition lists are written as follows:
-- | This is a definition list: -- -- [@foo@] The description of @foo@. -- -- [@bar@] The description of @bar@.
To produce output something like this:
The description of
The description of
Each paragraph should be preceded by the
“definition term” enclosed in square brackets.
The square bracket characters have no special meaning outside
the beginning of a definition paragraph. That is, if a
paragraph begins with a
[ character, then
it is assumed to be a definition paragraph, and the next
] character found will close the definition
term. Other markup operators may be used freely within the
A URL can be included in a documentation comment by
surrounding it in angle brackets:
<...>. If the output format supports
it, the URL will be turned into a hyperlink when
Sometimes it is useful to be able to link to a point in
the documentation which doesn't correspond to a particular
entity. For that purpose, we allow anchors to be
included in a documentation comment. The syntax is
label is the name of the anchor.
An anchor is invisible in the generated documentation.
To link to an anchor from elsewhere, use the syntax
module is the module name
containing the anchor, and
the anchor label. The module does not have to be local, it
can be imported via an interface.
We chose not to use this as the primary markup for
identifiers because strictly speaking the
character should not be used as a left quote, it is a grave accent.