如何在Haskell中启用死代码警告(GHC) [英] How to enable dead code warnings in Haskell (GHC)
问题描述
如何在Haskell中启用此功能? (可能吗?)例如,在下面的代码中,我想将 url2
标记为死代码,因为它不在主要
。
url1 =http://stackoverflow.com
url2 =http://stackexchange.com
main =打印url1
我看到了一些编译器标志的引用(例如 -fwarn-unused-binds
, -fwarn-name-shadowing
,和 -fwarn-hi-shadowing
),但它们都没有达到我想要的效果。
如果您限制,GHC会将 url2
报告为死码 -fwarn-unused-binds
例如:
模块Main(main)其中
...
如果你的模块头只是
模块Main其中
然后您隐式地导出所有内容, t con sider任何顶级绑定将被使用。
Some languages (like Go & Rust) require the programmer to be diligent in removing all dead code from the source. This has benefits in code maintainability and readability, if a bit extreme for some users.
How can I enable this feature in Haskell? (Is it possible?) For example, in the following code, I'd like url2
to be flagged as dead code because it isn't used in main
.
url1 = "http://stackoverflow.com"
url2 = "http://stackexchange.com"
main = print url1
I saw reference to some compiler flags (e.g. -fwarn-unused-binds
, -fwarn-name-shadowing
, and -fwarn-hi-shadowing
) but none of them seem to accomplish what I want.
GHC will report url2
as dead code with -fwarn-unused-binds
if you restrict the list of exports from the module appropriately, e.g.:
module Main(main) where
...
If your module header is just
module Main where
then you are implicitly exporting everything and so it can't consider any top-level binding to be unused.
这篇关于如何在Haskell中启用死代码警告(GHC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!