使用Cabal运行程序并传递参数

3
我可以使用cabal构建和运行一个简单的Haskell程序。
module Main where
import System.Environment ( getArgs )
main :: IO ()
main = do

   -- (input:_:_) <- getArgs
   print "Hello Oren"

当不需要任何参数时,一切都很顺利。
$ cabal build 1>/dev/null 2>/dev/null
$ cabal run
Up to date
"Hello Oren"

似乎可以向程序传递参数:
$ cabal run --help | sed -n '13,16p'
Extra arguments can be passed to the program, but use '--' to separate
arguments for the program from arguments for cabal. The executable is run in
an environment where it can find its data files inplace in the build tree.

然而,我似乎无法让它正常工作。
$ cabal run -- Oren 13 10              
cabal: Cannot run the package Oren, it is not in this project (either directly
or indirectly). If you want to add it to the project then edit the
cabal.project file.
1个回答

2
你需要明确地调用你想要运行的目标。例如,如果你只有一个可执行文件,你可以使用 "exes" 作为一个简写:
$ cabal run exes -- Oren 13 10

在阴谋文档的目标表单部分列出了编写目标的所有可能方式。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接