This is because ghci disables buffering, while a program compiled with ghc has line buffering by default. You can see this by running this:
import System.IO
main = print =<< hGetBuffering stdout
In ghci you see NoBuffering
while with runghc you get LineBuffering
. Since the newline character doesn't print until after the user input, the prompt doesn't either.
Fix it by adding hFlush stdout
after your prompt (or disable buffering with hSetBuffering stdout NoBuffering
, but that’s probably bad).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…