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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.