Haskell中无法识别的HLINT编译指示
我正在尝试禁用 HLint 给我的一些警告。根据文档,我应该能够在我的文件顶部添加一个编译指示。所以我尝试了以下方法:
{-# HLINT ignore #-}
module Main where
然而,这在运行时给了我一个错误stack build:
/Users/nene/somedir/src/Main.hs:1:1: warning: [-Wunrecognised-pragmas]
Unrecognised pragma
|
1 | {-# HLINT ignore #-}
| ^^^
似乎 pragma 实际上在我的编辑器(带有“Haskell”扩展名的 VSCode)中有效,但在运行stack.
回答
如果你想在没有任何警告的情况下使用编译指示,你可以ANN像这样使用编译指示:
{-# ANN module "HLint: ignore" #-}
但是,我建议使用常规注释而不是编译指示:
{- HLINT ignore -}
我更喜欢常规注释,因为它们没有像 pragma 那样奇怪的规则。事实上,文档指出:
对于
ANN编译指示,将它们放在任何导入语句之后很重要。如果您OverloadedStrings启用了扩展,则需要为注释提供显式类型,例如{-# ANN myFunction ("HLint: ignore" :: String) #-}. 该ANN编译指示还可以增加编译时间或造成比其他方式更需要重新编译,因为它们是由评估TemplateHaskell。对于
{-# HLINT #-}编译指示,GHC 可能会发出有关无法识别的编译指示的警告,可以使用-Wno-unrecognised-pragmas.
- @ReneSaarsoo: I think the only pragma you really need to be aware of as a beginner is `LANGUAGE`, which explicitly enables language features. You may also see `OPTIONS_GHC` sometimes for specifying extra compiler options. You can ignore others until you need them; they control more advanced optimisations, warnings, and type system features. Also, pragma names are case-insensitive, so you can write e.g. `{-# Language BlockArguments #-}` if you prefer.