相关疑难解决方法(0)

对GHC-Wall风格的影响

使用GHC警告被视为良好做法-Wall.但是,我发现修复这些警告会对某些类型的代码构造产生负面影响.

例1:

f >>如果我没有明确使用_ <- f表单,使用等号的do- not会产生警告:

Warning: A do-notation statement discarded a result of type Char.
         Suppress this warning by saying "_ <- f",
         or by using the flag -fno-warn-unused-do-bind
Run Code Online (Sandbox Code Playgroud)

我明白我可以忘记做一些事情f.但是,忽略结果是合理的(在解析器中很常见).使用时没有警告>>,对吧?使用_ <-比它应该更重.

例2:

使用可见函数的相同名称命名模式变量将给出:

Warning: This binding for `map' shadows the existing binding
           imported from Prelude
Run Code Online (Sandbox Code Playgroud)

当使用记录语法时,这会越来越严重,因为命名空间会被快速污染.解决方案是在模式表达式中提供备用名称.因此,为了避免警告,我最终使用了一个不太合适的名称.我觉得这不是一个足够好的理由.

我知道我可以使用-fno-warn-...选项,但我应该坚持使用-Wall吗?

warnings haskell coding-style compiler-warnings ghc

24
推荐指数
4
解决办法
3938
查看次数

标签 统计

coding-style ×1

compiler-warnings ×1

ghc ×1

haskell ×1

warnings ×1