使用ghc运行脚本(不是模块) [英] Run a script (not a module) with ghc

查看:145
本文介绍了使用ghc运行脚本(不是模块)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

然后可以运行它并通过执行$ b来获取终端中的输出
$ b

  ghc -e':script file.hs'

现在我在Windows上使用 ghc 8.0.1 ,这不起作用。如果我打开 GHCi 并键入,那么我可以得到输出结果吗? :script file.hs 。但我想在终端输出这些数据。



我不知道这是否是由于 ghc 或到操作系统。

解决方案

这适用于双引号:

  ghc -e:script file.hs


Previously I used ghc version < 8 on Linux and when I had a script in a file, say file.hs, like

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

then it was possible to run it and get the outputs in a terminal by doing

ghc -e ':script file.hs'

Now I'm using ghc 8.0.1 on Windows and this does not work anymore. Is there another way ?

I can get the outputs if I open GHCi and type :script file.hs. But I want these outputs in the terminal.

I don't know whether this is due to the upgrade of ghc or to the OS.

解决方案

This works with double quotes:

ghc -e ":script file.hs"

这篇关于使用ghc运行脚本(不是模块)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆