如何通过 Haskell 的 optparse-applicative 使用具有多个值的选项

How to use options with multiple values with Haskell's optparse-applicative

我有以下 Haskell 使用 optparse-applicative 的代码,它在运行时挂起。

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

问题与 many 组合器的使用有关,因为一旦我删除它,代码就可以正常运行。

这是一个错误还是我做错了什么?

谢谢!

我想,这里的问题出在默认值上。只需从解析器修饰符中删除 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.