In ghci, how to remove an existing binding?

99封情书 提交于 2019-12-10 17:31:38

问题


I am getting a "binding shadows the existing binding" error similar to the one from this question.

Prelude Api.Facility Control.Monad.IO.Class> let t = getBadgesNot 1 (Nothing) (Just 1)

<interactive>:55:5: warning: [-Wname-shadowing]
    This binding for ‘t’ shadows the existing binding
      defined at <interactive>:39:5

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?

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"

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


回答1:


Is there a way to remove the existing binding so that I can redefine t?

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

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

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.

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


来源:https://stackoverflow.com/questions/44894152/in-ghci-how-to-remove-an-existing-binding

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!