Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a program's command line arguments for GHCi?

Tags:

haskell

ghci

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!!

like image 836
gatoatigrado Avatar asked Jan 15 '12 03:01

gatoatigrado


People also ask

How do I run a program in Ghci?

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.)

What is command line argument program?

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.

How do I run a command line argument in CMD?

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 /? .


2 Answers

You can also set the command line arguments in ghci

ghci> :set args foo bar ghci> main 

or

ghci> :main foo bar 
like image 158
Daniel Fischer Avatar answered Sep 19 '22 20:09

Daniel Fischer


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 
like image 25
John Bartholomew Avatar answered Sep 18 '22 20:09

John Bartholomew