2012-11-08 42 views
17

使用GHCi時,我想知道如何在提示(重新)加載時使用-Wall選項。來自GHCi提示的加載警告

例如,在與警衛所示的Haskell Programming Tips 例子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) 

它說:「第一個問題是,它是幾乎不可能的編譯器檢查這樣的後衛是否詳盡,因爲警戒條件可能非常複雜(如果您使用-Wall選項,GHC會發出警告)。「

我知道我可以從命令行鍵入ghci -Wall some_file.hs,但是一旦出現提示,我不確定如何檢查警告是否需要重新加載。

我似乎無法找到答案後嘗試Google!

在此先感謝!

+2

你可以把它放到你的'.ghci'文件的便利。我有':set -Wall \ n:set -fno-warn-type-defaults \ n:set -fno-warn-unused-do-bind'來打開所有的煩人的警告。 –

+0

如果您第一次設置「-Wall」,我認爲它也將保持設置以進行任何重新加載... –

回答

22

在ghci中,輸入

:set -Wall 

,如果你想要把所有的警告了,你可以做

:set -w 

(注意小寫w。大寫將打開正常的警告。)

the user guide它說我們可以在命令提示符下使用任何ghc命令行選項,只要它們被列爲動態的,我們可以從the flag reference所有警告設置都是動態的。

下面是一個例子會話,使用「壞實施」上面:

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)