I am learning some Haskell and I came across this little program
reverseLines :: String -> String
reverseLines input =
unlines (map reverse (lines input))
main :: IO ()
main = interact reverseLines
This program will continue to ask the user for more input and cancel the input and print it on the screen.
Most of this is straight forward, but one thing I can’t wrap my head with is why this function continues to work and asks the user for more input, whereas if I just replaced the function reverseLineswith a function, just returning some line it will not happen.
This program will stop after one run:
foo input = "Stops"
main :: IO ()
main = interact foo
Why?
source
share