I have wasted several hours trying to fix simple Haskell program where I tried to ask the user to enter a string and then display it. The program looks like that:
main = do putStrLn "Enter something " entered <- getLine putStrLn ("You have entered " ++ entered)
After hours of chasing my tail and reading lots of Monad tutorials I have discovered that my program works fine in cmd prompt. Can you imagine my frustration at this point?
This SO question gave me a clue to try it in cmd: https://stackoverflow.com/questions/8361508/execution-order-with-not-what-i-expected?rq=1
Is it possible to fix eshell? If not what is the best way to develop Haskell on Windows with Emacs?
After a bit of experimenting I decided to start cmd.exe with a customised script that sets my environment for Haskell development. The following script starts my cmd:
set PATH=C:\msys64\mingw64\bin;C:\msys64\usr\bin;%PATH% set INCLUDE=c:/msys64/mingw64/include set XDG_DATA_DIRS=c:/msys64/mingw64/share set PKG_CONFIG_PATH=c:/msys64/mingw64/lib/pkgconfig set HASKELL_GI_GIR_SEARCH_PATH=c:/msys64/mingw64/share/gir-1.0 cd C:/Windows/System32/ cmd.exe
Using cmd sets my path correctly. I have tried a similar script that launches powershell, which gives me better autocompletion than cmd, but for some reason I can't make the PATH in powershell accept my script settings, other environment variables seem to be OK.
Following one commenter's question this is the version that works with eshell on Windows 10
import System.IO (hFlush, stdout) main = do putStrLn "Enter a string" hFlush stdout ln <- getLine putStrLn ("Yo have entered " ++ ln)
Note the use of hFlush stdout after first printing that was causing problems.