44

Suppose some Haskell file is executed with

runghc Queens.hs gecode_compile

Now, this fails, and I want to debug it with ghci. How do I pass the option gecode_compile into the program, so getArgs will read it correctly?

Thanks!!

3 Answers 3

79

You can also set the command line arguments in ghci

ghci> :set args foo bar
ghci> main

or

ghci> :main foo bar
1
  • 3
    yeah, too bad the shortcut doesn't turn on trace Jan 15, 2012 at 3:50
25

You can use the System.Environment.withArgs function to execute main with your desired arguments.

Here's an example session (irrelevant details elided):

$ ghci
GHCi, version 7.0.3: http://www.haskell.org/ghc/  :? for help
Prelude> import System.Environment
Prelude System.Environment> let main = getArgs >>= mapM_ putStrLn
Prelude System.Environment> withArgs ["hello", "world"] main
hello
world
14

You can use the :set command:

Prelude> :set args whatever

This will mean that getArgs returns ["whatever"].

So in your case you should just do this:

Prelude> :set args gecode_compile

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.