'Taking a path from stdin and using it as argument to readFile

As a learning strategy, I tried to modify Prelude interact function.

test.hs contents

interact' :: (String -> String) -> IO ()
interact' f = do
  path <- getContents
  s <- readFile path
  putStr (f s)

main :: IO ()
main = interact' id

test.txt contents

Hello World

Calling echo "test.txt" | runhaskell test.hs doesn't display Hello World. Am I overlooking something ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source