簡體   English   中英

從GHCi提示加載警告

[英]Warnings on load from GHCi prompt

當使用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)

它說:“第一個問題是編譯器幾乎不可能檢查這樣的警衛是否是詳盡無遺的,因為警衛條件可能是任意復雜的(如果你使用-Wall選項,GHC會警告你)。”

我知道我可以ghci -Wall some_file.hs鍵入ghci -Wall some_file.hs但是在提示符中我不確定如果我想重新加載,如何檢查警告。

嘗試Google之后,我似乎無法找到答案!

提前致謝!

在ghci中,輸入

:set -Wall

如果你想關閉所有警告,你可以這樣做

:set -w

(注意小寫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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM