[Haskell-cafe] Typed Configuration Files
sebf at informatik.uni-kiel.de
Fri Jan 8 07:53:53 EST 2010
Neil Mitchell's cmdargs package  is pretty neat. It can be used to
parse command-line arguments into a user-defined data structure.
Is there something similar for parsing config files?
There are a number of config file parsers on Hackage. But even the
most sophisticated one I found, ConfigFile by John Goerzen , only
yields primitive data like strings, booleans, and numbers. Did I
I'd like to write something like
do fc <- configFile ...
ac <- cmdArgs ...
let conf = fc `mappend` ac
where the type of `conf` is a user defined monoid.
I found that the fez-conf package  provides a function
`parseToArgs` which creates a list similar to the one returned by
`System.getArgs` from a config file. Neil, if you would add a function
to your cmdargs package that allows to specify the argument list, then
one could reuse your machinery to create typed config data from config
files too, right? Maybe along the lines of
do args <- parseToArgs <$> readFile "/my/conf"
conf <- cmdArgsWithDefault args "My Program" [myMode]
The new function `cmdArgsWithDefault` could require the return type to
be a monoid in order to allow users to specify themselves how to deal
with multiple options of the same kind.
Would that be reasonable or is there a better alternative?
Underestimating the novelty of the future is a time-honored tradition.
More information about the Haskell-Cafe