运行 带有 ghc 的脚本(不是模块)

Run a script (not a module) with ghc

以前我在 Linux 上使用 ghc 版本 < 8,当我在文件中有一个脚本时,比如 file.hs,比如

let x = "hello"
putStrLn x
double x=2*x
print $ double 2
double 3

然后可以运行它并通过

在终端中获得输出
ghc -e ':script file.hs'

现在我在 Windows 上使用 ghc 8.0.1,这不再有效了。还有其他方法吗?

如果我打开 GHCi 并输入 :script file.hs,我可以获得输出。但我想在终端中输出这些。

我不知道这是因为 ghc 升级还是 OS.

这适用于双引号:

ghc -e ":script file.hs"