我有以下使用 optparse-applicative 的 Haskell 代码,该代码在运行时挂起。
main :: IO ()
main = do
printf "Start...\n"
args <- execParser $ info args fullDesc
printf "Cmdline args: %s\n" (show args)
args :: Parser [Integer]
args = many (option auto
(short 'x'
<> value 1))
问题与使用许多组合器有关,因为一旦我删除它,代码就可以正常运行。
这是一个错误还是我做错了什么?
谢谢!
最佳答案
我认为,这里的问题在于默认值。只需从解析器修饰符中删除 value 1
即可。
来自 value
上的文档:
Note: Because this modifier means the parser will never fail, do not use it with combinators such as some or many, as these combinators continue until a failure occurs. Careless use will thus result in a hang.
关于haskell - 如何通过 Haskell 的 optparse-applicative 使用具有多个值的选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46542992/