[Haskell-cafe] Typed Configuration Files

Sebastian Fischer sebf at informatik.uni-kiel.de
Fri Jan 8 07:53:53 EST 2010

Dear Café,

Neil Mitchell's cmdargs package [1] 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 [2], only  
yields primitive data like strings, booleans, and numbers. Did I  
overlook something?

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 [3] 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?


[1] http://hackage.haskell.org/package/cmdargs
[2] http://hackage.haskell.org/package/ConfigFile
[3] http://hackage.haskell.org/package/fez-conf

Underestimating the novelty of the future is a time-honored tradition.

More information about the Haskell-Cafe mailing list