lef*_*out 8 haskell record compiler-warnings
这个模块
module Foo (Foo, qux) where
data Foo = Foo {bla::Int}
qux :: Foo
qux = Foo 37
Run Code Online (Sandbox Code Playgroud)
使用编译时会引起警告-Wall:
/tmp/wtmpf-file12937.hs:3:17: warning: [-Wunused-top-binds]
Defined but not used: ‘bla’
|
3 | data Foo = Foo {bla::Int}
| ^^^
Run Code Online (Sandbox Code Playgroud)
好的–如果bla只是一个独立的函数,这将很容易,应该通过移除来解决bla。但是,为了记录起见,这些字段不仅提供了可以使用的名称,还用作代码中的文档。
摆脱警告的首选方式是什么?
它应该是一个永久性的解决方案,最好保持记录不变,并且最好不要对模块的其余部分禁用任何警告。
为了避免这些,我通常在模块中添加如下定义:
_unused :: a
_unused = error "don't complain" bla
Run Code Online (Sandbox Code Playgroud)
不错的是,您可以将它们链接起来,如下所示:
_unused :: a
_unused = error "don't complain" bla bah foo bar
Run Code Online (Sandbox Code Playgroud)
这有点粗糙,但可以完成工作。
| 归档时间: |
|
| 查看次数: |
80 次 |
| 最近记录: |