Variable binding does not work in the REPL
Closed this issue · 7 comments
- I declare a type in the editor
- bind a variable of that type in the REPL
- nothing happens: GHCi reloads same prompt as beginning of session:
Ok, modules loaded: Main.
*Main> *Main>
I don't think you can define anything with let in the editor, though it should work in the REPL. I'm going to try to replicate this.
Sorry, typo. I tried both styles (with and without let
) in the repl of course.
This is because right now we are reloading the whole module eachtime we press return in the REPL
With our current model, we can't support variable bindings in the console which is definitely a drawback. In general, I don't believe there is a way to reload modules into ghci while keeping the local environment. Perhaps we could store a local .ghci_env.hs
file for a given session? This package also proposes a solution, but it also doesn't recommend being used for production.
@KitFreddura maybe it's worth a try, who knows 😄
So I worked on a branch, bug-fix/variables-in-repl, which has a fix for this. It checks if the file hasn't been modified on pressing enter in the console. If the file hasn't changed, the file keeps it's environment. If the file has changed, it needs to reload and the environment is reset. Please check it out, thanks!
Also, as a matter of style, maybe we should have the console clear on enter? It looks a bit odd when typing in say:
let x = 5
and it just hanging around in the console 😛
Edit: It seems that this branch breaks variables defined in a code cell though, so that needs to be sorted out
Seems to be fixed!
Irrelevant with new version, closing