Where does stack ghci store its history? Per this question it ought to be in ~/.ghc/ghci_history but that does not seem to be the target for all GHCi sessions invoked by stack within a project. (There surely must be concurrency issues if all sessions were writing to that file?) The user guide mentions the option -flocal-ghci-history but that is not invoked via stack by default.
The use case is: You have a project and tinker with some modules interactively. After a while you realize that you have done something useful in the session and would like to save the commands somewhere.
Obvious work-arounds are:
Alias stack ghci to stack ghci --ghci-options -flocal-ghci-history and inspect the .ghci_history file if needed
Start with an empty .hs file of your choice and keep re-compiling it (in the IDE of your choice)
But GHCi does always keep a (Haskeline?) history, so how do I get my hands on it from within a vanilla GHCi session?
For Stack, it just Rio.Process.exec’s the specified GHC executable with --interactive and other GHC flags/options. That is, I think Stack is just relying on that executable’s handling of concurrency issues (if any).
From experimentation:
GHCi reads from that history file when it starts; and
writes to the file with additions when it finishes; and
over-writes any file that has been written to by other GHCi which started and finished in the interim.
So that was my misconception: There is no trace of a still runnnig session’s history on disk. Unfortunately the history seems to be limited to 100 lines, whence one should not rely on the history alone.
Thanks, the linked issue summarizes the difficulties pretty well, that need to be overcome to persist the history on-the-fly. Thus it seems my work-around #2 is the safe way to go: Do not experiment in an interactive session when there is a chance you’ll need to persist the commands.