在ghci中,如何删除现有绑定? [英] In ghci, how to remove an existing binding?

查看:90
本文介绍了在ghci中,如何删除现有绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从类似于"我在会话的早期定义了现有的绑定,现在正尝试重新定义它. 是否可以删除现有绑定,以便重新定义t?

I defined the existing binding earlier in the session, and am now trying to redefine it. Is there a way to remove the existing binding so that I can redefine t?

我注意到在其他情况下,ghci在重新定义现有绑定时不会出错.例如

I notice that in other circumstances ghci does not error when redefining an existing binding. For example

Prelude> let t = 1
Prelude> let t = 2
Prelude> let t = "there"

为什么在某些情况下而不是在其他情况下重新定义现有绑定时ghci错误?

推荐答案

是否可以删除现有绑定,以便重新定义t?

否,您无法删除现有绑定.但是,您可以随时重新定义t,没问题.

No, you cannot remove the existing binding. However, you can redefine t at any time, no problem.

为什么在某些情况下而不是在其他情况下重新定义现有绑定时ghci错误?

Why does ghci error when redefining an existing binding in some cases and not in others?

因为您以不同的警告/错误设置运行了ghci;例如通过在命令行上传递-Wname-shadowing(可能是因为您通过ghal或stack运行了ghci,并且关联的项目在其.cabal文件中指定了此选项). N.B.除非与-Werror结合使用,否则-Wname-shadowing不应阻止您重新定义t,以将单纯的警告变成全面的错误.

Because you ran ghci with different warning/error settings; e.g. by passing -Wname-shadowing on the command line (perhaps because you ran ghci through cabal or stack, and the associated project specifies this option in its .cabal file). N.B. -Wname-shadowing should not prevent you from redefining t unless combined with -Werror to turn the mere warning into a full-blown error.

根据您是否使用let,行为似乎也有所不同.这可能是一个错误:

The behavior also appears to differ depending on whether you use let or not; this is probably a bug:

% ghci -Wname-shadowing -Werror
> let t=3
> let t=4
<interactive>:3:5: warning: [-Wname-shadowing]
    This binding for ‘t’ shadows the existing binding
      defined at <interactive>:1:5

<no location info>: error: 
Failing due to -Werror.
> t
3
> t=4
> t
4

这篇关于在ghci中,如何删除现有绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆