Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ghci: keep defined values in scope after module reload

Tags:

haskell

ghci

I am wondering if it is possible to keep assigned values in ghci when a module is reloaded?

For example i assign a value in ghci:

ghci> let x = 1

or

ghci> x <- getLine

After entering :r to reload an existing module x is not in scope anymore. Is it generally possible to keep the assignment available, like for example in the Python interpreter? (this is really convenient...)

Even tho that actually each line in ghci represents a function that is (monadically) bound to the next one I am still wondering if maintaining that state is possible.

like image 847
JHannes Avatar asked Oct 18 '12 17:10

JHannes


1 Answers

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

like image 200
MathematicalOrchid Avatar answered Oct 27 '22 15:10

MathematicalOrchid