-- From http://learnyouahaskell.com/input-and-output, somewhat modified main = interact (unlines . map reverseWords . lines) -- These are equivalent: -- interact (\ x -> unlines $ map reverseWords (lines x)) -- interact (\ x -> unlines (map reverseWords (lines x))) -- (unlines . map reverseWords . lines) reverseWords :: String -> String reverseWords = unwords . map reverse . words -- Note what happens for -- main = interact reverseWords -- This program *also* works, but prints its output only when the end -- of file is reached. You will not notice any difference if -- ./reverse-interact gets its input from a file (i.e., via input -- redirection from the shell) or from a Unix pipe. However, -- "interactive" line-by-line operation of the above main will not -- work. See loop3.hs (and loop2.hs, too) -- This happens because there's nothing to clue the IO actions in -- interact that newlines are somehow special. In the above main, -- on the other hand, the (pure) function lines (defined in Data.List, -- :i tells us--look up its code) causes a sequence of reads in -- interact.