
21 Jun
2008
21 Jun
'08
3:19 p.m.
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