我正在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。
我的错; 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
警告,因为我想要。