Is there an easy way to access REPL history (like a list) from GHCi?

Other repl for example. Octave , have special teams to view the history of teams. I find this very convenient (although whenever I use such a function, I ask myself: why didn’t I correctly define this command in the file in the first place?).

GHCi does not seem to have this capability, and I think it probably shouldn't be; such interactivity would make endevours, like managing from Emacs, more complex than they already are.

However, it is a fairly simple task to simply extract the whole story, and then use the usual Haskell to view it. Has anything like this been implemented anywhere else?

+8
haskell read-eval-print-loop ghci
source share
1 answer

Probably the best way to do this is a more cross-platform way, which could be turned into a nice little package to load into a .ghci file or something like that, but the quick and dirty way using haskeline pretty simple. You can just read the ghci_history file for your system, mine is located in C:/Users/bheklilr/AppData/Roaming/ghc/ghci_history , but I believe that in the * nix system it should be in ~/.ghci_history . Choose the right one for your system.

 > import System.Console.Haskeline.History > hist <- fmap $ readHistory "path/to/ghci_history" > putStrLn $ unlines hist 

Unfortunately, at least for me, it seems that the history file is not updated until GHCi exits, so for a specific session, hist should be the same (provided that you only have one instance of GHCi). In my opinion, this is a rather limited API, I think it would not be too difficult to reset the history of each command, or at least every pair of commands, but this has not been done.

Alternatively, you can use CTRL-R and several other commands to find your story, this is much more useful. This is especially useful because it will look for appropriate subtext.

+2
source share

All Articles