GHC警告在让绑定中无可辩驳的模式

问题描述 投票:0回答:1

我正在Haskell写一个国际象棋程序,在运行时测试时遇到了Irrefutable pattern failed...错误。

我有以下数据类型:

data Color = ...
data Piece = ...
data CPiece = CP Color Piece | Null

问题发生在:

let startPiece = getPiece board start in
  let CP startColor _ = startPiece in

getPiece返回CPiece,我知道我没有考虑Null构造函数,应该使用case getPiece board start of ...语句。

但是,为什么GHC没有产生任何警告?我打开了-Wall-Wincomplete-uni-patterns,我在Debian上使用GHC 8.0.2。

haskell
1个回答
0
投票

我的错; ghc默认运行在make mode,在尝试不同的开关时,我运行:

$ ghc -Wall file.hs
$ ghc -Wall -Wincomplete-uni-patterns file.hs

连续。 ghc的第二次调用不会编译file.hs,因为自第一次调用以来它已经被编译和未修改。

运行

$ touch file.hs
$ ghc -Wall -Wincomplete-uni-patterns file.hs

更新源文件的时间戳,然后编译产生Pattern match(es) are non-exhaustive警告,因为我想要。

© www.soinside.com 2019 - 2024. All rights reserved.