Is it possible to pass command line arguments when running Haskell code using `ghc -e`?

Intuitively, I've tried

$ ghc -e "import System.Environment" -e "getArgs" -- a b c
ghc: unrecognised flag: --
did you mean one of:
  -n
  -F
  -v

Usage: For basic information, try the `--help' option.
$

      

... without success.

I expected the output to be along the lines ["a","b","c"]

.

The docs here don't seem to mention any way to pass cli arguments.

AFAIK pipes in stdio work as expected.

And, perhaps, if it is not possible to pass arguments with ghc -e

, perhaps with, ghci

it is possible to supply both some code and some arguments, run and then exit?

+3


source to share


1 answer


To answer the second part of the question:



Prelude> :help :main
 Commands available from the prompt: 
   :main [<arguments> ...]     run the main function with the given arguments
Prelude> let main = System.Environment.getArgs >>= print
Prelude> :main foo bar
["foo","bar"]

      

+1


source







All Articles