record field names vs. -fwarn-unused-binds

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

record field names vs. -fwarn-unused-binds

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.
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: record field names vs. -fwarn-unused-binds

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.


On Tue, Nov 3, 2015 at 6:47 PM, Evan Laforge <[hidden email]> wrote:
[ 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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: record field names vs. -fwarn-unused-binds

Henning Thielemann
In reply to this post by Evan Laforge

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.
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: record field names vs. -fwarn-unused-binds

Michael Orlitzky
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.


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: record field names vs. -fwarn-unused-binds

Evan Laforge
In reply to this post by Thomas Miedema
On Tue, Nov 3, 2015 at 10:42 AM, Thomas Miedema <[hidden email]> wrote:
> 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
<[hidden email]> wrote:
> 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.
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe