Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么Haskell NoBuffering选项似乎仍在缓冲?_Haskell_Ghci - Fatal编程技术网

为什么Haskell NoBuffering选项似乎仍在缓冲?

为什么Haskell NoBuffering选项似乎仍在缓冲?,haskell,ghci,Haskell,Ghci,我在ghci中加载了一个包含以下内容的文件: h <- openFile "somefile.txt" ReadMode hSetBuffering h NoBuffering 如果我运行hGetChar,我将获得预期的“A” 现在,如果我使用cat(cat>somefile.txt)将内容更改为以下内容,并再次运行hGetChar,我会预期为“Z”,但它会返回“B”: AZZZZZZZZ BufferMode仅在写入句柄时相关,而在读取句柄时不相关 从中的[注意缓冲读取]: 输入文档

我在ghci中加载了一个包含以下内容的文件:

h <- openFile "somefile.txt" ReadMode
hSetBuffering h NoBuffering
如果我运行hGetChar,我将获得预期的“A”

现在,如果我使用cat(cat>somefile.txt)将内容更改为以下内容,并再次运行hGetChar,我会预期为“Z”,但它会返回“B”:

AZZZZZZZZ

BufferMode
仅在写入句柄时相关,而在读取句柄时不相关

从中的
[注意缓冲读取]


输入文档似乎已过时。

如果您的文本编辑器写入临时文件,然后通过
somefile.txt将其重命名,则这是可能的。在这种情况下,所有现有句柄仍将引用(现在没有名字)旧文件。好的一点,我用更具体的场景修改了这个问题您如何使用
cat
cat
仅写入标准输出,因此除非您将stdout从
cat
重定向到该文件,否则它不会更改文件。您是否再次尝试
hGetChar
?表示“hLookAhead操作意味着即使没有缓冲的句柄也可能需要一个单字符的缓冲区。”如果它仍以这种方式运行,我怀疑在操作系统级别上发生了缓冲,您可能需要在读取新数据之前读取整个旧文件。不过我对这一点不太了解,所以希望有更多的人能够回答。好的:获取新内容的技巧:
pos
AZZZZZZZZ
Note that the buffering mode (haBufferMode) makes no difference when
reading data into a Handle.  When reading, we can always just read all
the data there is available without blocking, decode it into the Char
buffer, and then provide it immediately to the caller.