假设某个Haskell文件被执行:
runghc Queens.hs gecode_compile
现在,这个操作失败了,我想用 ghci
进行调试。我该如何将选项 gecode_compile
传递给程序,以便 getArgs
能够正确读取它?
谢谢!
你也可以在ghci中设置命令行参数
ghci> :set args foo bar
ghci> main
或者ghci> :main foo bar
您可以使用System.Environment.withArgs
函数来执行带有所需参数的main
函数。
以下是一个示例会话(省略了不相关的细节):
$ 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
您可以使用:set
命令:
Prelude> :set args whatever
这意味着getArgs
将返回["whatever"]
。因此,在你的情况下,你只需要这样做:Prelude> :set args gecode_compile