作為一種學習策略,我嘗試修改 Preludeinteract功能。
test.hs內容
interact' :: (String -> String) -> IO ()
interact' f = do
path <- getContents
s <- readFile path
putStr (f s)
main :: IO ()
main = interact' id
test.txt內容
Hello World
來電echo "test.txt" | runhaskell test.hs不顯示Hello World。我忽略了什么嗎?
uj5u.com熱心網友回復:
echo "test.txt"生成字串test.txt\n,并且您沒有名為 的檔案test.txt\n,只有一個名為test.txt. 要么在 Haskell 中使用getLine而不是getContents不獲取換行符,要么在 shell 中使用而printf不是echo首先不發出換行符。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/427238.html
