[Haskell-cafe] record field names vs. -fwarn-unused-binds
Evan Laforge
qdunkan at gmail.com
Tue Nov 3 17:47:56 UTC 2015
[ ccing haskell-cafe since while it's a ghc flag, I'll bet most
compilers have an equivalent ]
I really like -fwarn-unused-binds because it frequently finds bugs
where I forgot to call something or use some value. If I put an
export list on, it can find dead functions I forgot to delete.
However, there's one case where it frequently gives false positives,
and that's unused record field names. The problem is that I sometimes
use record field names as documentation, but the record itself is
internal and small, so I'm comfortable using positional pattern
matching to open it (and in fact that can be safer, since then
warn-unused-binds will make sure I used all the fields). But GHC sees
these as unused functions, so it warns about them. I can work around
by putting underscores on field names I haven't used yet, but it's a
hassle to go edit them when I want to use them. The warning can be
useful if it indicates an unused field, but since fields can also be
extracted via the positional syntax it's not reliable. The other use
of the warning for dead code or functions you forgot to use doesn't
apply to record accessors because they're trivial and compiler
generated.
So, would it be reasonable to exclude record field accessors from
-fwarn-unused-binds? Or is there another way to work around it? I
guess GHC doesn't have a "suppress warning" pragma like Java does, but
even if we did it wouldn't be much better than changing the name, and
more likely to get stale.
More information about the Haskell-Cafe
mailing list