gpt4 book ai didi

haskell - Haddock:用默认类文档替换怪癖的实例函数的文档

转载 作者:行者123 更新时间:2023-12-04 15:34:57 24 4
gpt4 key购买 nike

考虑以下示例:

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

通过黑线鳕运行时,函数 getput出现了,但他们使用的是 MonadState 的默认文档。如何在我的模块中包含我自己的文档?

(你可以通过运行 cabal haddock 在 repo here 上看到我的意思)

最佳答案

你不能。

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

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


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

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

关于haskell - Haddock:用默认类文档替换怪癖的实例函数的文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17758681/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com