I'm using the Replit website to run a Haskell program using GHC. I'm typing code into the editor and running it using the Run button, not just running lines of code using GHCi. I'm running into weird problems with output whenever I use the getLine function, even in extremely simple programs. For example, running the program
main = do ans <- getLine
putStrLn ans
and typing hi at the input prompt prints hi twice instead of once:
cabal v1-run
Preprocessing executable 'Cabal-example' for Cabal-example-0.1.0.0..
Building executable 'Cabal-example' for Cabal-example-0.1.0.0..
[1 of 1] Compiling Main ( Main.hs, dist/build/Cabal-example/Cabal-example-tmp/Main.o )
Linking dist/build/Cabal-example/Cabal-example ...
Running Cabal-example...
hi
hi
hi
The problem gets even weirder when I try to disable input/output buffering in the main function (I needed to do this for a larger program I was working on):
cabal v1-run
Preprocessing executable 'Cabal-example' for Cabal-example-0.1.0.0..
Building executable 'Cabal-example' for Cabal-example-0.1.0.0..
[1 of 1] Compiling Main ( Main.hs, dist/build/Cabal-example/Cabal-example-tmp/Main.o )
Linking dist/build/Cabal-example/Cabal-example ...
Running Cabal-example...
hi
hi^Jhi
I have tested this code on other websites and the code works normally. What am I missing here?