Haskell Console IO in Notepad ++

I recently started to learn Haskell. I have this code

module Main where import IO main = do hSetBuffering stdin LineBuffering putStrLn "Please enter your name: " name <- getLine putStrLn ("Hello, " ++ name ++ ", how are you?") 

I use the GHC compiler with the notepad ++ editor. The problem is that the interaction is as follows:

The process has begun →>
Vlad
Please enter your name:
Hello Vlad, how are you? & L; <<The process is completed.

As you can see, the output is written only after entering something. This was a bit unexpected, because I was sure that the program would first ask for my name, then I would go into it, and then he would say hello. Well, what exactly happens if I run exe manually, but I will not start it using Notepad ++ and use its console shell ...

How can I make notepad ++ display the output when it should, and not all this before the program terminates? Is it possible?

+4
source share
2 answers

Try setting stdout to LineBuffering! Also, loading your program in ghci instead of the runnign compiled version does not seem to require any buffering at all ...

By the way, I did not know about the console in the nuclear power plant - thanks for pointing me to it!

+7
source

I am not familiar with notepad ++, but a quick and hacky method will probably do

 hFlush stdout 

after each putStrLn. You can even do the following method:

 nppPutStrLn s = putStrLn s >> hFlush stdout 
+2
source

Source: https://habr.com/ru/post/1309315/


All Articles