Haskell IO with Interaction and Map

I am trying to create an interactive Haskell program using function interactc map.

This is what I get in ghci (as far as I can tell, since all the tutorials explain the use interact- except the result).

*Module> interact $ unlines . map (++ "!") . lines
tteesstt
!

Please note that what is actually happening is that every character that I type instantly repeats, and after pressing the Return button an exclamation mark appears. I, however, expected this:

*Module> interact $ unlines . map (++ "!") . lines
test
test!

It works fine if I use the same program structure, but filterinstead map.

+5
source share
2 answers

, ghci . , , . foo.hs

main = interact $ unlines . map (++ "!") . lines

runhaskell foo.hs, , , , Haskell .

+8

FUZxxl, .

GHCi, hSetBuffering

Prelude> :m +System.IO
Prelude System.IO> hSetBuffering stdout LineBuffering 
Prelude System.IO> interact $ unlines . map (++"!") . lines
hello
hello!
^CInterrupted.
Prelude System.IO> 
+2

All Articles