What does a Haskell comment starting with `{- |` generally mean?

dan picture dan · Jan 11, 2013 · Viewed 16.9k times · Source

I see Haskell multi-line comments that sometimes start with {- | instead of just {-.

Does leading with the pipe character inside the comment mean something by convention?

Answer

Lily Ballard picture Lily Ballard · Jan 11, 2013

The | at the start of a comment is Haddock syntax that begins a documentation annotation. An example from the Haddock documentation is:

-- |The 'square' function squares an integer.
square :: Int -> Int
square x = x * x

It also goes on to say

The “-- |” syntax begins a documentation annotation, which applies to the following declaration in the source file. Note that the annotation is just a comment in Haskell — it will be ignored by the Haskell compiler.