How to enable dead code warnings in Haskell (GHC)

Some languages ​​(like Go and Rust) require the programmer to try to remove all dead code from the source. This has advantages in the maintenance and readability of the code, if for some users it is a bit extreme.

How to enable this feature in Haskell? (Is this possible?) For example, in the following code, I would like url2 be marked as dead code because it is not used in main .

 url1 = "http://stackoverflow.com" url2 = "http://stackexchange.com" main = print url1 

I saw a link to some compiler flags (e.g. -fwarn-unused-binds , -fwarn-name-shadowing and -fwarn-hi-shadowing ), but none of them seem to do what I want.

+8
haskell ghc
source share
1 answer

GHC will tell url2 as dead code with -fwarn-unused-binds if you restrict the export list from the module accordingly, for example:

 module Main(main) where ... 

If your module title is just

 module Main where 

then you implicitly export everything and therefore it cannot assume that the top-level binding is not used.

+17
source share

All Articles