What's the recommended way to have module-private record types without setting off -Wunused-top-binds?
Asked Answered
C

1

9

This module

module Foo (Foo, qux) where

data Foo = Foo {bla::Int}

qux :: Foo
qux = Foo 37

causes a warning when compiled with -Wall:

/tmp/wtmpf-file12937.hs:3:17: warning: [-Wunused-top-binds]
    Defined but not used: ‘bla’
  |
3 | data Foo = Foo {bla::Int}
  |                 ^^^

Ok – if bla were just a standalone function, this would be easy and should be fixed by removing bla. But for a record, the fields do more than just provide a name that can be used, they also serve as documentation in the code.

What is the preferred way to get rid of the warning?

It should be a permanent solution, should preferrably keep the record as-is, and preferrably not disable any warnings for the rest of the module.

Concern answered 18/9, 2019 at 15:45 Comment(3)
I usually prefix them with underscore _blahSeller
Possible duplicate of How to [temporarily] suppress "defined but not used" warnings?Archaean
I like the underscore solution, since it's consistent with my use of underscore variables for unused function arguments that I want to document.Hybridism
P
6

To avoid these, I usually add a definition like this to the module:

_unused :: a
_unused = error "don't complain" bla

The nice thing is you can chain them, like so:

_unused :: a
_unused = error "don't complain" bla bah foo bar

It's kind of crude, but gets the job done.

Prieto answered 18/9, 2019 at 16:27 Comment(3)
The infinite-curry-unfolding trick is really quite neat. I'm not sure like the :: a signature, but that can easily be changed.Concern
Yeah, you can give it whatever type you want obviously.Prieto
I'd recommend this solution only if you can't or don't want to put underscores on the record names themselves. For example I've used a similar trick with yesod/persistent data types generated with template haskellSeller

© 2022 - 2024 — McMap. All rights reserved.