This is due to different buffering behaviour in GHCi and GHC. GHCi has stdin (standard input stream) using NoBuffering
by default, and GHC-compiled binaries / runhaskell
use LineBuffering
by default. If you explicitly do
hSetBuffering stdin NoBuffering
in your Haskell program, you'll be able to reproduce the GHCi behaviour. If you do
hSetBuffering stdin LineBuffering
in GHCi, you'll have lots of unwanted side effects, but can reproduce the runhaskell
behaviour.