How to see the current working directory in WinGHCi

Nawaz picture Nawaz · Jun 28, 2012 · Viewed 15.2k times · Source

I've started to teach myself Haskell, and for that I've installed The Haskell Platform for Windows. I'm using WinGHCi as of now. I learned that it has command :cd which is used to change directory. But the question is, how would I know which directory I'm currently in? Without knowing that first why would I want to change directory. I searched a lot but couldn't find the answer.

Please tell me if there is a way to know the current working directory. Preferably I would like to configure the command prompt itself to show the current directory, pretty much like Linux's Console.


Following @Daniel's suggestion, I did these:

  • Since I worked on Windows 7, there is no .ghci file (I think it is for Unix-like OS), so I created a file ghci.conf in C:\Users\Apelles\AppData\Roaming\ghc folder, as it is instructed here.
  • Copy pasted the script from Daniel's answer to ghci.conf.
  • Then I started ghci.exe which is the console-like window. I noticed that it loaded few more modules than it usually used to load before. Here is the snapshot:

enter image description here

As you can see it loads more modules, and the last line says,

Can't parse prompt string. Use Haskell syntax.

What does it mean? Which line is causing problem (from the following script)?

let cur fill = do { cwd <- System.Directory.getCurrentDirectory; return (":set prompt \"" ++ cwd ++ fill ++ " \""); }
:def doprompt (\_ -> cur ">")
:def mycd (\dir -> System.Directory.setCurrentDirectory dir >> cur ">")
:doprompt

Also, if I rename ghci.conf file to some random name, and then start ghci.exe, it loads these modules: enter image description here

As I said before, it loads less number of modules, which means with ghci.conf, ghci.exe does something successfully, but fails at some point. How to fix that?

Answer

jp093121 picture jp093121 · Feb 27, 2014

System.Directory.getCurrentDirectory from the directory package.