6

考虑以下示例:

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

当通过 haddock 运行时,这些函数getput显示出来,但它们使用的是 MonadState 的默认文档。如何在我的模块中包含我自己的文档?

(你可以在这里cabal haddock运行repo来了解我的意思)

4

1 回答 1

3

你不能。

您可以做的是记录您的实例。

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

这将使描述显示在instances生成的框的一侧。这应该最好是简短的,但它确实可以让你做一些事情,比如如果你真的需要的话,可以将用户指向实现字段的函数的文档,就像问题的评论者所建议的那样。

就个人而言,我认为像这样记录每个字段并没有多大意义:字段的用途应该从类定义的文档和对实例的注释中清楚。

于 2014-02-19T05:32:23.653 回答