[Haskell-cafe] Safe way to parse arguments?

Henning Thielemann lemming at henning-thielemann.de
Sun Jun 22 16:45:51 EDT 2008

On Sat, 21 Jun 2008, Xiao-Yong Jin wrote:

> Hi,
> I'm wondering how usually you parse command line arguments
> list safely.  If the given argument is wrong, the program
> can still print out some error information instead of giving
> something like
> Prelude.read: no parse

It's generally not a good idea to call 'read' on user data. 'read' expects 
well-formed input. Calling 'read' with other input is a programming 
_error_. If the user enters garbage, this is an _exception_ and this must 
be handled with 'reads' or 'maybeRead' as others suggested.

More information about the Haskell-Cafe mailing list