There's a lot of confusion going on here. Let's try to clear things up.
I tried getContents. But getContents wait for user to type all lines before processing them.
The most likely thing here is that you've compiled your program, and didn't notice that the default buffering for output was block-buffering. This is easy to fix:
f line = putStrLn ("Hi, " ++ line ++ "!")
main = do
hSetBuffering stdout LineBuffering -- or use NoBuffering
putStrLn "Enter some names."
input <- getContents
mapM_ f (lines input)
You should use NoBuffering if you don't plan on printing a whole line (including newline) after each line of user input.
For a more precise answer, we'll need to see the code you tried that didn't work.
Q: But in my first try, I use: "interact show" and it doesn't work. Do you know why?
A: Because show will not return any output until its entire input has been exhausted.
This answer is not quite correct. The real answer is that show produces a string with no newlines in it! (Though the character sequence ['\\','\n'] does show up sometimes if the input is more than one line long.) So, for interact show, you really must use NoBuffering on stdout. For example, if you use this:
main = do
hSetBuffering stdout NoBuffering
interact show
...the program will print a bit more output after each line. You might also want to set stdin's buffering to NoBuffering (instead of the default LineBuffering), since show is productive enough that it really can produce more output after each keystroke.
getContentsreturns a lazy list of characters. Perhaps the consuming function is too strict.