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!!
Open a command window and navigate to the directory where you want to keep your Haskell source files. Run Haskell by typing ghci or ghci MyFile. hs. (The "i" in "GHCi" stands for "interactive", as opposed to compiling and producing an executable file.)
Command line arguments are nothing but simply arguments that are specified after the name of the program in the system's command line, and these argument values are passed on to your program during program execution.
Command line syntax Commands provide the action, or list of actions separated by semicolons, that should be implemented. If no command is specified, then the command is assumed to be new-tab by default. To display a help message listing the available command line arguments, enter: wt -h , wt --help , wt -? , or wt /? .
You can also set the command line arguments in ghci
ghci> :set args foo bar ghci> main
or
ghci> :main foo bar
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With