Haddock 超链接并且没有关于冗余导入的警告

发布于 2025-01-01 08:07:02 字数 888 浏览 0 评论 0原文

我的项目中有一个虚拟模块,其唯一目的是保存库其余部分的 Haddock 文档。事实上,我不需要导入此模块中的任何内容,但如果我不导入其他模块,Haddock 不会将函数名称超链接到其模块。

我的模块看起来像这样

{- |

Lots of Haddock text here... it references 'someFunction'.

-}
module TopLevelDoc () where

import Other.Module.With.SomeFunction

现在,如果我构建项目,我会收到此警告:

    Warning: The import of `Other.Module.With.SomeFunction' is redundant
           except perhaps to import instances from `Other.Module.With.SomeFunction'
         To import instances alone, use: import Other.Module.With.SomeFunction()

如果我删除导入或将它们设为 (),Haddock 不会将 someFunction 超链接到其文档。如果我按原样保留此类导入,我会收到很多错误警告,这是我不喜欢的。我不想在整个项目中抑制这种警告,它可能对除了这个模块之外的任何其他模块都有用。

问题:

  1. 如何在构建时获得超链接的 Haddock 输出而不出现此类警告?
  2. 是否可以针对每个文件禁用警告? (就像我可以使用 .cabal 中的 ghc-options 进行全局操作一样)

I have a dummy module in my project, whose sole purpose is to hold Haddock documentation for the rest of the library. In fact I don't need to import anything in this module, but if I don't import other modules, Haddock doesn't hyperlink function names to their modules.

My module looks like this

{- |

Lots of Haddock text here... it references 'someFunction'.

-}
module TopLevelDoc () where

import Other.Module.With.SomeFunction

Now if I build the project, I get this warning:

    Warning: The import of `Other.Module.With.SomeFunction' is redundant
           except perhaps to import instances from `Other.Module.With.SomeFunction'
         To import instances alone, use: import Other.Module.With.SomeFunction()

If I remove imports or make them (), Haddock doesn't hyperlink someFunction to its documentation. If I leave such imports as is, I get lots of false warnings, which I don't like. And I don't want to suppress this kind of warning for the entire project, it may be useful for any other module but this one.

Questions:

  1. How do I get hyperlinked Haddock output without such warnings when building?
  2. Is it possible to disable warnings on per-file basis? (like I can do it globally with ghc-options in .cabal)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浪荡不羁 2025-01-08 08:07:02

要消除未使用的导入警告,您可以在文件顶部放置一个编译指示:

{-# OPTIONS_GHC -fno-warn-unused-imports #-}

您可以通过显式限定它们来链接到不在范围内的标识符:

还可以通过给出实体的完整限定名称来引用不在当前模块范围内的实体:

<前><代码>-- |标识符“MT”不在范围内

如果 MT 不在范围内,那么 Haddock 将简单地发出一个指向从模块 M 导出的实体 T 的链接(而不检查 M 或 MT 是否存在)。

Haddock 用户指南

但是,这可能会使您的文档源代码相当难看,并且模块限定条件不会从输出中删除,因此我建议关闭警告。

To silence the unused import warning, you can put a pragma at the top of your file:

{-# OPTIONS_GHC -fno-warn-unused-imports #-}

You can link to to identifiers that aren't in scope by explicitly qualifying them:

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

If M.T is not otherwise in scope, then Haddock will simply emit a link pointing to the entity T exported from module M (without checking to see whether either M or M.T exist).

The Haddock User Guide

However, this will probably make your documentation source quite ugly, and the module qualifications aren't removed from the output, so I'd recommend turning off the warnings instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文