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

Either use reads instead, and deal with the case where there is no
parse. Or use the safe library, on hackage, and something like:

import Safe

readNote "please enter a number" x

Where if x is "test", you'll get:

Program error: Prelude.read: no parse, please enter a number, on "test"

Or use readDef:

readDef (error "Please enter a number") x

Which will just give you:

Program error: Please enter a number

Or, readMay, which will return a Nothing if you fail, which you can
deal with as you wish.

Thanks

Neil
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to