我可以禁用“非穷举模式匹配”吗?只警告lambdas? [英] Can I disable the "non-exhaustive pattern matches" warning only for lambdas?
问题描述
我可以禁用非穷尽模式匹配警告吗?仅适用于lambdas?
Can I disable the non-exhaustive pattern matches warning only for lambdas?
我喜欢一般的警告,但不是像这样的实际lambda文字:
I like the warning in general, but not for actual lambda literals like this:
map (\(x:xs)->...) ls
我认为这段代码很清楚我希望 ls
的所有值总是至少有一个元素,并且没有简单的方法来处理错误情况。拉姆达。 (我想我可以将模式匹配移动到 case
语句中,但那会很丑。)
I think this code makes it pretty clear that I expect all the values of ls
to always have at least one element, and there is no neat way to handle the error case in the lambda. (I guess I could move the pattern match into a case
statement, but that would just be ugly.)
推荐答案
是的,但只在GHC 7.2以上;通过 -fno-warn-incomplete-uni- (例如在你的Cabal文件的
ghc-options
字段中,或者在 { - #OPTIONS_GHC# - }
在您的文件顶部使用pragma)。
Yes, but only in GHC 7.2 onwards; pass -fno-warn-incomplete-uni-patterns
(e.g. in your Cabal file's ghc-options
field, or in an {-# OPTIONS_GHC #-}
pragma at the top of your file).
但是,这也会禁用模式绑定的警告,所以让x = x
中的Nothing不会产生警告。 case
语句不受影响。
However, this will also disable the warning for pattern bindings, so let Just x = Nothing in x
won't produce a warning. case
statements are unaffected.
这篇关于我可以禁用“非穷举模式匹配”吗?只警告lambdas?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!