In a typical Haskell way, setting up a CLI parser can be extremely smooth if you know what to do (e.g. you can automatically create on like here: Generic Programming - The Haskell Guide) but a bit confusing if you don’t.
If you are just working with IO avoiding applicatives then I’d say you start with
-- This functions takes the list of arguments and returns something of your interest
-- the list of arguments look like ["--verbose","2","--color", "always", "-f" etc...]
yourOwnSimpleParser :: [String] -> SomeUserDefinedType
yourOwnSimpleParser = undefined
main = do
list_of_arguments <- getArgs
yourOwnSimpleParser list_of_arguments
...
Once you convice yourself writing your own parser is a bad idea, go with optparse-applicative. Despite of its applicative interface, you’ll see it is actaully very easy to use.
Then you should checkout Iris too, which is built on top of optparse-applicative and is a more complete CLI framework, with good documentation. Probably you need a little bit of experience to use it headachelessly (is this even a word?)
You can also use optparse-generic, a wrapper on optparse-applicative. You can take a look at the haddock in the main module, it explains basic concepts.
Note that @wiz’s suggestion needs {-# LANGUAGE ApplicativeDo #-} enabled. Other than that, this is my preferred approach - optparse-applicative + ApplicativeDo.
Wow, I hadn’t seen that package yet. It looks like the author has spent a lot of effort subverting Haskell. Although I don’t think I’d say more is gained than lost.
Interesting. Would you mind explain why/how cmdargs subverts Haskell? I guess you mean it is not very “haskellonic”. I guess optparse-applicative is more haskellonic? Why?
Please excuse my dumb questions, but I’m just starting out with Haskell.
You can compare examples for optparse-applicative that just rides Applicative and Monoid instances with example for cmdargs with its use of type reflection and partial values.
With one you can open the library source and get a good understanding of how it was made even you’re fresh off the tutorial, but not so with the other.