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

后端 未结 3 606
忘了有多久
忘了有多久 2021-01-31 15:10

Suppose some Haskell file is executed with

runghc Queens.hs gecode_compile

Now, this fails, and I want to debug it with ghci. How

相关标签:
3条回答
  • 2021-01-31 15:31

    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
    
    0 讨论(0)
  • 2021-01-31 15:38

    You can also set the command line arguments in ghci

    ghci> :set args foo bar
    ghci> main
    

    or

    ghci> :main foo bar
    
    0 讨论(0)
  • 2021-01-31 15:45

    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
    
    0 讨论(0)
提交回复
热议问题