我想知道重新加载模块时是否可以在 ghci 中保留分配的值?
例如,我在 ghci 中赋值:
ghci> let x = 1
或者
ghci> x <- getLine
进入:r
重新加载现有模块后x
不再在范围内。通常是否可以保持分配可用,例如在 Python 解释器中?(这个真的很方便……)
即使实际上 ghci 中的每一行都代表一个(单子)绑定到下一个函数的函数,我仍然想知道是否可以保持该状态。
I'm not aware of any way of doing this.
The trouble is that you could have some variable bound to a value of a certain type, edit the source to remove that type, and hit reload. Now you have a variable of a type that no longer exists.
Still, you would think it shouldn't be too hard to detect that, and discard just the variables that don't make sense any more. (The really fun part is presumably when a type still exists but has a different number of fields now, or something like that...)