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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With