This more of a style question, rather than a how to.
So I've got a program that needs two command line arguments: a string and an integer.
I implemented it this way:
main = do
args@(~( aString : aInteger : [] ) ) <- getArgs
let parsed@( ~[(n,_)] ) = reads aInteger
if length args /= 2 || L.null parsed
then do
name <- getProgName
hPutStrLn stderr $ "usage: " ++ name ++ " <string> <integer>"
exitFailure
else do
doStuffWith aString n
While this works, this is the first time I've really used command line args in Haskell, so I'm not sure whether this is a horribly awkward and unreadable way to do what I want.
Using lazy pattern matching works, but I could see how it could be frowned upon by other coders. And the use of reads to see if I got a successful parse definitely felt awkward when writing it.
Is there a more idiomatic way to do this?