6

Consider the following example:

instance (Monad m) => MonadState s (ChronoT s e m) where

    -- | Returns the present-day state.
    get   = ChronoT $ do
        (ChronoS _ s _) <- get
        return s

    -- | Set the present-day state directly, erasing the past and future for
    --   safety. See also 'paradox'.
    put x = ChronoT $ do
        (ChronoS _ _ _) <- get
        put $ mkChronoS x

When run through haddock, the functions get and put show up, but they are using the default documentation from MonadState. How do I include my own documentation for them in my module?

(You can see what I mean by running cabal haddock over the repo here)

kvanbere
  • 3,289
  • 3
  • 27
  • 52
  • 6
    As far as I know, you can't, haddock doesn't document instance declarations (except by listing the instance as defined). You could make top-level entities `chronoGet` and `chronoPut`, document (and export) them, and define the instance `...where get = chronoGet; put = chronoPut`. That's of course not very satisfactory. – Daniel Fischer Jul 20 '13 at 09:17

1 Answers1

3

You can't.

What you can do is document your instance.

-- | You can have a brief description here
instance (Monad m) => MonadState s (ChronoT s e m) where
…

This will make the description show up to the side of the instances box generated. This should preferably be brief but it does let you do things such as point the user to documentation of the functions implementing the fields if you really need to, like the commenter on the question suggests.

Personally, I think that it doesn't make much sense to document each field like this: what the fields are meant to do should be clear from documentation of the class definition and the comment on the instance.

Mateusz Kowalczyk
  • 2,036
  • 1
  • 15
  • 29
  • where is the instances box? (I'm using haddock 2.14.3) – sam boosalis Oct 09 '14 at 04:09
  • 1
    Here I was refering to the box that shows under the data type definition. Here is an example for Maybe, also illustrating a comment that would have been on the instance itself: http://fuuzetsu.co.uk/images/1412881296.png – Mateusz Kowalczyk Oct 09 '14 at 19:02