record field names vs. -fwarn-unused-binds

[ 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.

Through a patch
https://git.haskell.org/ghc.git/commitdiff/aead01902e1c41e85b758dbafd15e60d0...
by Oleg Grenrus (phadej), GHC 8 will have the following new flags:
-fwarn-unused-top-binds
-fwarn-unused-local-binds
-fwarn-unused-pattern-binds
So you'll be able to pick and choose.
On Tue, Nov 3, 2015 at 6:47 PM, Evan Laforge
[ 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. _______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users

On Tue, Nov 3, 2015 at 10:42 AM, Thomas Miedema
Through a patch by Oleg Grenrus (phadej), GHC 8 will have the following new flags: -fwarn-unused-top-binds -fwarn-unused-local-binds -fwarn-unused-pattern-binds
So you'll be able to pick and choose.
I suppose a record accessor would be considered a top bind? I still
kind of like getting warnings about those, just not the ones from
records...
On Wed, Nov 4, 2015 at 6:56 AM, Henning Thielemann
I do it this way and I do not consider it a work-around. The underscore is just the shortest way to say that a record field name is not used. It's shorter than any pragma could be.
I agree, that's what I meant by "not much better than changing the name". I guess it would have to be yet another flag like -fwarn-unused-record-accessors... not sure if it would be worth it though, considering it's a relatively minor issue.

On Tue, 3 Nov 2015, Evan Laforge wrote:
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.
I do it this way and I do not consider it a work-around. The underscore is just the shortest way to say that a record field name is not used. It's shorter than any pragma could be.

On 11/04/2015 09:56 AM, Henning Thielemann wrote:
On Tue, 3 Nov 2015, Evan Laforge wrote:
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.
I do it this way and I do not consider it a work-around. The underscore is just the shortest way to say that a record field name is not used. It's shorter than any pragma could be.
There are libraries that do magic based on the field name (Groundhog comes to mind). In those cases you have to name the field appropriately even if you're not going to use it, so the ability to shutup the warning will be appreciated.
participants (4)
-
Evan Laforge
-
Henning Thielemann
-
Michael Orlitzky
-
Thomas Miedema