Haskell 中无法识别的 HLINT 杂注
Unrecognised HLINT pragma in Haskell
我正在尝试禁用 HLint 给我的一些警告。 According to docs 我应该可以在我的文件顶部添加一个 pragma。所以我尝试了以下方法:
{-# HLINT ignore #-}
module Main where
但是当 运行 stack build
:
时给我一个错误
/Users/nene/somedir/src/Main.hs:1:1: warning: [-Wunrecognised-pragmas]
Unrecognised pragma
|
1 | {-# HLINT ignore #-}
| ^^^
似乎 pragma 在我的编辑器中确实有效(VSCode 带有“Haskell”扩展名),但在 运行 stack
.[=16 时无法识别=]
如果你想在没有任何警告的情况下使用 pragma,你可以像这样使用 ANN
pragma:
{-# ANN module "HLint: ignore" #-}
但是我建议使用常规注释而不是 pragma:
{- HLINT ignore -}
我更喜欢常规注释,因为它们不像 pragma 那样有奇怪的规则。事实上 the documentation 注释:
For ANN
pragmas it is important to put them after any import statements. If you have the OverloadedStrings
extension enabled you will need to give an explicit type to the annotation, e.g. {-# ANN myFunction ("HLint: ignore" :: String) #-}
. The ANN
pragmas can also increase compile times or cause more recompilation than otherwise required, since they are evaluated by TemplateHaskell
.
For {-# HLINT #-}
pragmas GHC may give a warning about an unrecognised pragma, which can be suppressed with -Wno-unrecognised-pragmas
.
我正在尝试禁用 HLint 给我的一些警告。 According to docs 我应该可以在我的文件顶部添加一个 pragma。所以我尝试了以下方法:
{-# HLINT ignore #-}
module Main where
但是当 运行 stack build
:
/Users/nene/somedir/src/Main.hs:1:1: warning: [-Wunrecognised-pragmas]
Unrecognised pragma
|
1 | {-# HLINT ignore #-}
| ^^^
似乎 pragma 在我的编辑器中确实有效(VSCode 带有“Haskell”扩展名),但在 运行 stack
.[=16 时无法识别=]
如果你想在没有任何警告的情况下使用 pragma,你可以像这样使用 ANN
pragma:
{-# ANN module "HLint: ignore" #-}
但是我建议使用常规注释而不是 pragma:
{- HLINT ignore -}
我更喜欢常规注释,因为它们不像 pragma 那样有奇怪的规则。事实上 the documentation 注释:
For
ANN
pragmas it is important to put them after any import statements. If you have theOverloadedStrings
extension enabled you will need to give an explicit type to the annotation, e.g.{-# ANN myFunction ("HLint: ignore" :: String) #-}
. TheANN
pragmas can also increase compile times or cause more recompilation than otherwise required, since they are evaluated byTemplateHaskell
.For
{-# HLINT #-}
pragmas GHC may give a warning about an unrecognised pragma, which can be suppressed with-Wno-unrecognised-pragmas
.