Haskell 用于执行表达式的堆栈命令行标志
Haskell stack command line flag for executing an expression
如果我有一个简单的 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
事实上你已经有了这个 flag: 它只是:
-e expr
Evaluate expr
; see eval-mode for details
所以你可以这样写:
ghci <b>-e</b> 'putStrLn "hello world"'
事实上,如果您使用 stack ghci
,您只需使用您的应用程序打开 ghci
,但 -e
标志不是 "stack-specific"。
例如:
$ ghci -e 'putStrLn "hello world"'
hello world
如果您在某一时刻检查 $ stack --help
,您会看到
eval Evaluate some haskell code inline. Shortcut for
'stack exec ghc -- -e CODE'
所以与其这样做
$ stack exec ghc -- -e 'putStrLn "hello world"'
hello world
你可能会喜欢
$ stack eval 'putStrLn "hello world"'
hello world
如果我有一个简单的 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
事实上你已经有了这个 flag: 它只是:
-e expr
Evaluate
expr
; see eval-mode for details
所以你可以这样写:
ghci <b>-e</b> 'putStrLn "hello world"'
事实上,如果您使用 stack ghci
,您只需使用您的应用程序打开 ghci
,但 -e
标志不是 "stack-specific"。
例如:
$ ghci -e 'putStrLn "hello world"'
hello world
如果您在某一时刻检查 $ stack --help
,您会看到
eval Evaluate some haskell code inline. Shortcut for
'stack exec ghc -- -e CODE'
所以与其这样做
$ stack exec ghc -- -e 'putStrLn "hello world"'
hello world
你可能会喜欢
$ stack eval 'putStrLn "hello world"'
hello world