[Haskell-cafe] handling non-string command line arguments

Erik Hesselink hesselink at gmail.com
Sat Jun 28 20:34:16 UTC 2014


If you want to use getOpt, you could produce options of type 'OptDescr
(Either String (Options -> Options))', that is, for a command line
argument, either produce an error, or some modification of your
options.

It is my experience that sometimes you will need a second pass even if
you do this, because there are some errors that require the value of
multiple options to check.

Erik

On Sat, Jun 28, 2014 at 9:28 PM, Johan Larson <johan.g.larson at gmail.com> 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.
>
> I could use getOpt as a first pass with string arguments and then turn the
> strings into validated numbers in a second pass, but that's a bit awkward.
> Alternately I could use the options records with Options -> IO Options
> functions. But both of these solutions treat type mismatches differently
> from other options errors.
>
> Has anyone found a cleaner solution?
>
> --
> Johan Larson -- Toronto, Canada
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list