gat*_*ado 12 haskell pattern-matching ghc
我正在寻找一个可以警告特定不完整模式的pragma.它会使编译器失败,并带有以下(假设的)代码:
{-# FAILIF incomplete-patterns #-}
f :: Int -> Int
f 0 = 0
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用Arrows编写"编译器",并且知道模式匹配已完成将有助于隔离错误.谢谢!
Don*_*art 11
您可以通过以下方式要求警告,包括不完整的模式-Wall:
{-# OPTIONS_GHC -Wall #-}
module A where
f :: Int -> Int
f 0 = 0
Run Code Online (Sandbox Code Playgroud)
产量:
A.hs:6:1:
Warning: Pattern match(es) are non-exhaustive
In an equation for `f':
Patterns not matched: GHC.Types.I# #x with #x `notElem` [0#]
Run Code Online (Sandbox Code Playgroud)
或者更具体地说,在-fwarn-incomplete-patterns适当的位置-Wall.
没有什么能够在每个表达式的基础上工作:您目前仅限于每个模块.