【问题标题】:Warnings on load from GHCi prompt来自 GHCi 提示的加载警告
【发布时间】:2012-11-08 23:08:09
【问题描述】:

在使用 GHCi 时,我想知道在从提示符(重新)加载时如何使用 -Wall 选项。

例如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,但是一旦在提示符中,我不确定如果我想重新加载如何检查警告。

我尝试谷歌后似乎无法找到答案!

提前致谢!

【问题讨论】:

  • 为方便起见,您可以将其放入您的.ghci 文件中。我有:set -Wall\n :set -fno-warn-type-defaults\n :set -fno-warn-unused-do-bind 可以打开除烦人的警告之外的所有警告。
  • 如果你第一次设置-Wall,我想它也会在任何重新加载时保持设置......

标签: haskell warnings ghci


【解决方案1】:

在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)

【讨论】:

    猜你喜欢
    • 2021-02-09
    • 2015-01-15
    • 1970-01-01
    • 1970-01-01
    • 2017-10-17
    • 2018-03-05
    • 1970-01-01
    • 2015-07-28
    • 2015-12-22
    相关资源
    最近更新 更多