[Haskell-cafe] ghc warn-unused-imports

Evan Laforge qdunkan at gmail.com
Mon Mar 24 13:44:36 EDT 2008


So it appears that GHC will warn about "unused" imports when you
import qualified if you could have gotten the symbol from somewhere
else.  For instance, if you write:

import qualified Control.Monad.Trans as Trans
import qualified Control.Monad.Writer as Writer

and use "Trans.lift", it will complain because you could have used
"Writer.lift".  Then if you go import State, it will want you to use
State.liftIO instead of Trans.liftIO (Writer doesn't have liftIO).
Now, one question is why these modules are exporting random stuff from
Trans, but in general the practice of warning when you use qualified
imports seems not only misleading (since if you comment out the import
your code breaks, and it's not obvious where it wanted you to get the
symbol), but brittle since a messy export list on some module you
import can suddenly trigger a flood of warnings.

So I'd suggest that if you say "import qualified M" and then use
"M.something", then "M is unused" msgs shouldn't appear.
warn-unused-imports is genuinely useful most of the time, so I don't
like to put on -fno-warn-unused-imports.

Is there a better way to suppress the "false positives" here?


More information about the Haskell-Cafe mailing list