【发布时间】:2021-11-16 16:13:17
【问题描述】:
我正在尝试打开一个文件并将第一行移到最后,如下所示:
-- Moves the first line in a file to the end of the file (first line becomes last line)
flyttLn :: FilePath -> IO ()
flyttLn fn = do
fh <- openFile fn ReadMode
content <- hGetContents fh
--putStrLn content
let
(l1:rest) = lines content
newContent = unlines (rest++[l1])
hClose fh
fh2 <- openFile fn WriteMode
hPutStr fh2 newContent
hClose fh2
由于惰性评估,这给了我一个错误。所以基于this的问题,我首先尝试打印文件的内容,然后重新编写它们。哪个有效,除了我不想在终端中打印整个文件。所以我尝试像这样导入System.IO.Strict
import qualified System.IO.Strict as SIO
但是 VS Code 给了我一个错误提示
Could not find module ‘System.IO.Strict’
It is not a module in the current program, or in any known package.not found
我曾尝试寻找类似的问题,但我只找到this的问题,并没有帮助我解决我的问题。
如何正确打开文件并编辑其内容,而无需在终端中打印整个文件?如何正确导入 System.IO.Strict?
【问题讨论】:
标签: haskell visual-studio-code