Skip to content

The logic behind the `unused-imports` warning is nonsense and a plague to the Haskell community

With -Wunused-imports, included in -Wall, GHC warns me (1) if I explicitly import an identifier from somewhere that is already implicitly imported from somewhere else, typically Prelude.

That is in most cases not what I want to be warned of. What I want to be warned of is this:

(2) I am explicitly importing an identifier that is unused, i.e., never referenced in my code.

But (1) is what we are all spending (wasting) our time on when it is triggered by changes in the Haskell ecosystem, that is, reexporting more things from Prelude etc.

To have (1) esp. in -Wall (combined with the volatility of base) is causing a lot of friction in the development process and wasting developer time of talented people on silly trivialities.

Something has to be done about this. Most urgently, (1) has to be removed from -Wall.

  1. Drop (1) from -Wunused-imports altogether. If this is too drastic:
  2. Package (2) in a new warning -Wactually-unused-imports and use this new warning in -Wall rather than -Wunused-imports.

Trigger: The process around adding liftA2 to Prelude.

Prior art: https://www.snoyman.com/blog/2020/11/haskell-bad-parts-2/

Haskell has a dumb set of default warnings enabled. [...]

So of course, we all turn on -Wall. Because we're good kids. We want to do the right thing. And this, of course, turns on unused import warnings. And because each new release of GHC and every library on Hackage likes to mess with us, we are constantly exporting new identifiers from different modules.

The amount of time I have spent adding weird hacks to account for the fact that <> is suddenly exposed from Prelude, and therefore my import Data.Monoid ((<>)) isn't necessary, is obscene. The introduction of fiddly CPP to work around this sucks. In fact, this all sucks. It's horrible.

I didn't realize how bad it was until I spent more time writing Rust. It reminded me that I never had these problems back as a Java developer. Or C++. This has been a Haskell-only problem for me.

Related issues:

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information