[英]GHC warning for irrefutable pattern in let binding
我在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 ...
的case getPiece board start of ...
。
但是,GHC為什么不發出任何警告? 我已經打開-Wall
和-Wincomplete-uni-patterns
,並且在Debian上使用GHC 8.0.2。
我的錯; ghc
默認情況下在make模式下運行,在嘗試不同的開關時,我運行了:
$ 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
如我所希望的那樣Pattern match(es) are non-exhaustive
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.