[Haskell-cafe] handling non-string command line arguments
Albert Y. C. Lai
trebla at vex.net
Tue Jul 1 20:57:40 UTC 2014
On 14-06-28 03:28 PM, Johan Larson wrote:
> I've been looking at choices for parsing command line arguments,
> including getOpt. The examples I can find focus on string arguments,
> whereas I am interested in numbers. In the application at hand, it is
> particularly important to issue clear error messages when arguments
> don't parse as numbers or are out of range.
My https://github.com/treblacy/random-read has an example of realistic
arguments using optparse-applicative. It goes as far as
random-read --prob=2/3 file1 file2 file3...
The 2/3 there has to be a rational number between 0 and 1 in the syntax
"numerator/denominator". If you give "234" or "abc", you get one error
message. If you give "30/7", you get a different error message.
More information about the Haskell-Cafe
mailing list