gpt4 book ai didi

haskell hFlush 没有按照我期望的方式工作

转载 作者:行者123 更新时间:2023-12-02 08:40:54 25 4
gpt4 key购买 nike

我正在尝试让一个程序使用 hFlush 读取整个文件,以避免我遇到的与惰性 IO 有关的问题。

readHandle <- openFile fileName ReadMode
hSetBuffering readHandle $ BlockBuffering (Just 2048)
fileText <- hGetContents readHandle
hFlush readHandle
hClose readHandle

这只是给我错误:hFlush:非法操作(句柄已关闭)

谁能帮我理解发生了什么

最佳答案

你的期望是错误的。通常,除了显式关闭句柄外,您不应在 hGetContents 调用后使用句柄。来自黑线鳕:

Computation hGetContents hdl returns the list of characters corresponding to the unread portion of the channel or file managed by hdl, which is put into an intermediate state, semi-closed. In this state, hdl is effectively closed, but items are read from hdl on demand and accumulated in a special list returned by hGetContents hdl.

关于haskell hFlush 没有按照我期望的方式工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16577853/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com