If I have a simple Haskell one-liner, what's the flag in ghc or ghci that could execute this from the command line?
I'm looking for something like:
stack ghci -e 'putStrLn "hello world"'
Similar to
$ R --quiet -e "cat('hello world')"
> cat('hello world')
hello world>
or
$ python -c "print('hello world')"
hello world
Edit for 'ghci -e' debug
(This question is resolved with an excellent answer already, but just debugging that the flag seems like it /should/ work above...)
Weirdly couldn't get the seemingly supported ghci -e working for me. Testing it is not just my machine, I also ran this on Ubuntu and had the same issue:
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"'
Then
$ docker build .
Produced...
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
stack eval 'putStrLn "hello world"'