Sar*_*all 18 warnings haskell ghci
当使用GHCi时,我想知道如何-Wall在(重新)从提示符加载时使用该选项.
例如,在Haskell编程提示 的3.3节中,带有防护装置的示例如下:
-- Bad implementation:
fac :: Integer -> Integer
fac n | n == 0 = 1
| n /= 0 = n * fac (n-1)
-- Slightly improved implementation:
fac :: Integer -> Integer
fac n | n == 0 = 1
| otherwise = n * fac (n-1)
Run Code Online (Sandbox Code Playgroud)
它说:"第一个问题是编译器几乎不可能检查这样的警卫是否是详尽无遗的,因为警卫条件可能是任意复杂的(如果你使用-Wall选项,GHC会警告你)."
我知道我可以ghci -Wall some_file.hs从命令行键入但是在提示符中我不确定如果我想重新加载,如何检查警告.
尝试Google之后,我似乎无法找到答案!
提前致谢!
And*_*ewC 26
在ghci中,输入
:set -Wall
Run Code Online (Sandbox Code Playgroud)
如果你想关闭所有警告,你可以这样做
:set -w
Run Code Online (Sandbox Code Playgroud)
(注意小写w.大写将打开正常警告.)
在用户指南中,它说我们可以在命令提示符下使用任何ghc命令行选项,只要它们被列为动态,我们可以从标志引用中看到所有警告设置都是动态的.
这是一个示例会话,使用上面的"错误实现":
Prelude> :l temp.hs
[1 of 1] Compiling Main ( temp.hs, interpreted )
Ok, modules loaded: Main.
(0.11 secs, 6443184 bytes)
*Main> :set -Wall
*Main> :l temp.hs
[1 of 1] Compiling Main ( temp.hs, interpreted )
temp.hs:3:1:
Warning: Pattern match(es) are non-exhaustive
In an equation for `fac': Patterns not matched: _
Ok, modules loaded: Main.
(0.14 secs, 6442800 bytes)
Run Code Online (Sandbox Code Playgroud)