Frege putStr 刷新行为不同于 Haskell 或 Java

Frege putStr flushing behavior is different from Haskell or Java

假设您提示用户输入 putStrgetLine 的组合:

main = do
    putStrLn "A line with line termination" -- printed correctly
    putStr   "A line without line termination, e.g. to prompt for input: " -- NOT printed
    line <-  getLine
    putStrLn ("You entered: " ++ line)

与 Haskell 相反,弗雷格不打印第二行(使用 putStr 而不是 putStrLn)。这种丢失冲洗的行为是故意的吗?

如果 Frege 偏离了 Haskell 的行为,我认为它会模仿 Java 的行为。一个概念上相似的例子:

public static void main(String[] args) {
    System.out.println("A line with line termination");
    System.out.print("A line without line termination, e.g. to prompt for input: ");
    String line = new java.util.Scanner(System.in).nextLine();
    System.out.println("You entered: " + line);
}

然而,这表现得像 Haskell 变体,即 System.out.print 立即被刷新。

提前感谢您的任何反馈!

PS:可以使用最新的 Eclipse 插件以及 IntelliJ/Gradle.

重现(错误?)行为

您的 Java 代码使用 System.out,这是一个 PrintStream。 Frege 代码使用 PrintWriter。

这两个 类 在冲洗方面的工作方式略有不同。来自 PrintWriter 的文档:

Unlike the {@link PrintStream} class, if automatic flushing is enabled it will be done only when one of the println, printf, or format methods is invoked, ..

因此,对于您的 Frege 代码,您必须在 print 之后添加一个 stdout.flush 以使其立即出现。

请随时提出问题,请求使 Frege 与这方面的 Haskell 行为保持一致。 (我们可以让 print 保持原样,但让 putStr 自动添加 flush。)