如果我有一个简单的Haskell单行程序,那么ghc或ghci中可以从命令行执行此操作的标志是什么?
stack ghci -e 'putStrLn "hello world"'
类似
$ R --quiet -e "cat('hello world')"
> cat('hello world')
hello world>
$ python -c "print('hello world')"
hello world
为“ghci-e”调试进行编辑
(这个问题已经用一个很好的答案解决了,但只是调试一下,上面的标志似乎是/应该/工作的…)
ghci -e
为我工作。测试它不仅仅是我的机器,我也在Ubuntu上运行了它,并且遇到了同样的问题:
FROM ubuntu:18.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install --yes curl \
&& curl -sSL https://get.haskellstack.org/ | sh \
&& export HOME=/root/.local/bin:$HOME \
&& stack ghci -e 'putStrLn "hello world"'
$ docker build .
产生。。。
Stack has been installed to: /usr/local/bin/stack
WARNING: '/root/.local/bin' is not on your PATH.
For best results, please add it to the beginning of PATH in your profile.
Invalid option `-e'
Usage: stack ghci [TARGET/FILE] [--ghci-options OPTIONS] [--ghc-options OPTIONS]
[--flag PACKAGE:[-]FLAG] [--with-ghc GHC] [--[no-]load]
[--package ARG] [--main-is TARGET] [--load-local-deps]
[--[no-]package-hiding] [--only-main] [--trace] [--profile]
[--no-strip] [--[no-]test] [--[no-]bench] [--help]
Run ghci in the context of package(s) (experimental)
The command '/bin/sh -c apt-get update && apt-get install --yes curl && curl -sSL https://get.haskellstack.org/ | sh && export HOME=/root/.local/bin:$HOME && stack ghci -e 'putStrLn "hello world"'' returned a non-zero code: 1