gpt4 book ai didi

haskell - 来自 GHCi 提示的加载警告

转载 作者:行者123 更新时间:2023-12-03 13:28:27 24 4
gpt4 key购买 nike

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

例如在 Haskell Programming Tips 的第 3.3 节中
带有 guard 的示例如下:

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

如果你想关闭所有警告,你可以这样做
:set -w

(注意小写 w 。大写将打开正常警告。)

the user guide它说我们可以在命令提示符下使用任何 ghc 命令行选项,只要它们被列为动态,我们可以从 the flag reference 中看到所有警告设置都是动态的。

这是一个示例 session ,使用上面的“错误实现”:
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)

关于haskell - 来自 GHCi 提示的加载警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13299501/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com