(typed) list of argument from a program using optp

2019-08-28 21:22发布

Is there a way to extract a list of names and types from a command line program, made using optparse-applicative ?

I am +/- looking for some function of type ParserInfo a -> [(String,TypeRep)]

1条回答
老娘就宠你
2楼-- · 2019-08-28 21:51

No, there is no way. The relevant bits are:

data ParserInfo a = ParserInfo   
    { infoParser :: Parser a
    , -- ...
    }

data Parser a
  = forall x . MultP (Parser (x -> a)) (Parser x)
  | forall x . BindP (Parser x) (x -> Parser a)
  | -- ...

Since the xs of MultP and BindP are existentially quantified and do not carry a Typeable constraint, the information about the types used at the leaves of a Parser a tree is lost at runtime.

查看更多
登录 后发表回答