(typed) list of argument from a program using optparse-appplicative

旧街凉风 提交于 2019-12-25 02:16:27

问题


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:


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.



来源:https://stackoverflow.com/questions/51406985/typed-list-of-argument-from-a-program-using-optparse-appplicative

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!