haskell - Parsing "enum" options with optparse-applicative -
how implement parser example grep --help:
--binary-files=type assume binary files type; type 'binary', 'text', or 'without-match' assuming have
data binaryfiles = binary | text | withoutmatch how write parser? option auto seems kludge since read supposed "inverse" show, , i'd keep derived instance show binaryfiles.
use str instead of auto:
binfile :: readm binaryfiles binfile = str >>= \s -> case s of "binary" -> return binary "text" -> return text "without-match" -> return withoutmatch _ -> readererror "accepted binary file types 'binary', 'text', , 'without-match'."
Comments
Post a Comment